簡體   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