helloWorldz.js
次のようなfile というファイルにディレクティブを作成しました。
'use strict';
angular.module('components')
.directive('helloWorld', function () {
return {
restrict : 'E',
template : '<span>Hello World</span>'
};
});
私app.js
のルートを含む私のファイルは次のようになります:
'use strict';
angular.module('mmApp', ['components'])
.config(function ($routeProvider) {
$routeProvider
.when('/designs', {
templateUrl: 'views/designs.html',
controller: 'MainCtrl'
})
.when('/blog', {
templateUrl: 'views/blog.html',
controller: 'MainCtrl'
})
.otherwise({
redirectTo: '/'
});
});
完了していない私のコントローラmain.js
は次のようになります:
'use strict';
angular.module('mmApp', [])
.controller('MainCtrl', function ($scope) {
$scope.designTiles = [
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
];
});
Chrome Dev ToolshelloWorldz.js
は、正常にロードされていることを示しています。下記参照
コントローラーの後にディレクティブ コードを配置し、その後に引数としてmain.js
渡すと、ディレクティブ コードが機能することがわかります。変更されたコントローラーは次のとおりです。['components']
mmApp
main.js
'use strict';
angular.module('mmApp', ['components'])
.controller('MainCtrl', function ($scope) {
$scope.designTiles = [
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
{ imageURL : "", title : "IMAGE" },
];
});
angular.module('components', [])
.directive('helloWorld', function () {
return {
restrict : 'E',
template : '<span>Hello World</span>'
}
});
私のディレクティブを含むモジュールでapp.js
正常に呼び出されないのはなぜですか? これは、に接続できないという可能性のある問題ですか?components
helloWorld
app.js
helloWorldz.js
また、grunt を使用してすべてをコンパイルしていることにも言及する必要があります。