[英]custom AngularJS directive not working
I am making a custom directive in AngularJS 1.4.3. 我正在AngularJS 1.4.3中创建自定义指令。 Below is my directive code. 下面是我的指令代码。
'use strict';
angular.module('psFramework').directive('psFramework', function () {
return {
transclude: true,
scope: {
},
controller: 'psFrameworkController',
templatesUrl: 'ext-modules/psFramework/psFrameworkTemplate.html'
}
});
Here is my controller psFrameworkController
这是我的控制器psFrameworkController
'use strict';
angular.module('psFramework').controller('psFrameworkController',
['$scope',
function ($scope) {
}
]);
My module psFrameworkModule
我的模块psFrameworkModule
'use strict';
angular.module('psFramework', ['psMenu', 'psDashboard']);
And templates psFrameworkTemplate.html
, which is very simple 还有模板psFrameworkTemplate.html
,这非常简单
<h1>Hello</h1>
When I put <ps-framework></ps-framework>
tags in my index.html
file then it somehow does not render the template. 当我将<ps-framework></ps-framework>
标记放入index.html
文件中时,它以某种方式无法呈现模板。
Here is my index.html
这是我的index.html
<body class="container-fluid">
<ps-framework></ps-framework>
</body>
It's templateUrl
NOT templatesUrl
and I like to suggest to add the restrict
property too: 这是templateUrl
不是templatesUrl
,我也建议添加restrict
属性:
'use strict';
angular.module('psFramework').directive('psFramework', function () {
return {
restrict: 'E',
transclude: true,
scope: {
},
controller: 'psFrameworkController',
templateUrl: 'ext-modules/psFramework/psFrameworkTemplate.html'
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.