指令:获取在templateUrl功能ATTR范围值 [英] Directive: Get attr scope-value in the templateUrl function

查看:103
本文介绍了指令:获取在templateUrl功能ATTR范围值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想打造的指令:

module.directive('templater', function () {
return {
    restrict: 'A',
    replace: true,
    templateUrl: function (element, attrs) {
        return attrs.templater;
    }
};
});

但是,正如你可能知道,在这个HTML:

but, as you may know, in this HTML:

<div 
    ng-repeat="item in items" 
    templater="item.template">
</div>

访问 attrs.templater 只是给 item.template ,而不是实际的模板URL字符串。

accessing attrs.templater simply gives item.template instead of the actual template url string.

如何访问里面的 attrs.templater 中的数据没有链接功能里面去?
我想利用 templateUrl 函数的简单,也避免在链接功能回流开销。

How do you access the data inside attrs.templater without going inside the linking function? I want to leverage the simplicity of the templateUrl function, also, avoid the reflow overhead in the linking function.

推荐答案

编辑:我原来的假设是错误的

EDITED: My original assumption was wrong.

由于 item.template 是有意义仅在一个范围的范围内,并且自该模板取/编译发生在某个时间点,当存在关于范围没有信息似乎没有要去取之前链接阶段模板的方法。

Since item.template is meaningful only in the context of a scope and since the template-fetching/compiling happens at a point in time when there is no info regarding scopes there doesn't seem to be a way to fetch the template prior to the linking phase.

这篇关于指令:获取在templateUrl功能ATTR范围值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆