相关疑难解决方法(0)

Angular.js指令动态templateURL

我在routeProvider模板中有一个自定义标记,用于调用directive模板.该version范围将填充该属性,然后调用正确的模板.

<hymn ver="before-{{ week }}-{{ day }}"></hymn>
Run Code Online (Sandbox Code Playgroud)

这首赞美诗有多个版本,基于它的周和日.我期待使用该指令来填充正确的.html部分.该变量未被读取templateUrl.

emanuel.directive('hymn', function() {
    var contentUrl;
    return {
        restrict: 'E',
        link: function(scope, element, attrs) {
            // concatenating the directory to the ver attr to select the correct excerpt for the day
            contentUrl = 'content/excerpts/hymn-' + attrs.ver + '.html';
        },
        // passing in contentUrl variable
        templateUrl: contentUrl
    }
});
Run Code Online (Sandbox Code Playgroud)

有在摘录目录多个文件被标记before-1-monday.html,before-2-tuesday.html...

angularjs angularjs-directive

169
推荐指数
4
解决办法
18万
查看次数

标签 统计

angularjs ×1

angularjs-directive ×1