繁体   English   中英

自定义AngularJS指令不起作用

[英]custom AngularJS directive not working

我正在AngularJS 1.4.3中创建自定义指令。 下面是我的指令代码。

'use strict';

angular.module('psFramework').directive('psFramework', function () {
    return {
        transclude: true,
        scope: {

        },
        controller: 'psFrameworkController',
        templatesUrl: 'ext-modules/psFramework/psFrameworkTemplate.html'
    }
});

这是我的控制器psFrameworkController

'use strict';

angular.module('psFramework').controller('psFrameworkController',
    ['$scope',
        function ($scope) {

        }
    ]);

我的模块psFrameworkModule

'use strict';

angular.module('psFramework', ['psMenu', 'psDashboard']);

还有模板psFrameworkTemplate.html ,这非常简单

<h1>Hello</h1>

当我将<ps-framework></ps-framework>标记放入index.html文件中时,它以某种方式无法呈现模板。

这是我的index.html

<body class="container-fluid">
    <ps-framework></ps-framework>
</body>

这是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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM