我剛剛開始使用Foundation for Apps,但我遇到了問題將角度控制器添加到單獨的文件夾中並使用它們。應用程序的基礎:爲angularjs控制器,服務等創建單獨的文件
我有這樣的現有結構在我資產的JS文件夾:
js/
app.js //this has all the controllers etc. by chaining
,但我希望它是
js/
app.js
controllers/
home.controller.js
main.controller.js
我不想讓一個大的js文件通過鏈接我的控制器,服務等來開發。我想要一個更具模塊化結構的指定。
當我把它改成了模塊化結構,我得到了以下三個錯誤:
1. 'HomeCtrl' not defined.
2. Uncaught SyntaxError: Unexpected token < at the 1st line of home.controller.js
3. Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:8079/assets/js/home.controller.js". at the point where I am including 'home.controller.js' in index.html
這裏是我的模板:
---
name: home
url:/
controller: HomeCtrl
---
<div class="grid-container">
<h1>Welcome to Foundation for Apps!</h1>
<p class="lead">This is version <strong>1.1 Weisshorn</strong>.</p>
</div>
home.controller.js:
app.controller('HomeCtrl', ['$scope', function($scope) {
$scope.temp = 'hello';
}]);
個app.js:
var app = angular.module('application', [
'ui.router',
'ngAnimate',
'foundation',
'foundation.dynamicRouting',
'foundation.dynamicRouting.animations'
])
.config(config)
.run(run)
;
config.$inject = ['$urlRouterProvider', '$locationProvider'];
function config($urlProvider, $locationProvider) {
$urlProvider.otherwise('/');
$locationProvider.html5Mode({
enabled:false,
requireBase: false
});
}
function run() {
FastClick.attach(document.body);
}
爲了解決這個我試過參照添加在gulpfile.js我控制器參考this
我還提到this,但我仍然無法得到它的工作。任何想法我做錯了什麼?