Angular.js 指令模板使用来自父/继承范围的变量 [英] Angular.js directive template using variable from parent/inherited scope

查看:26
本文介绍了Angular.js 指令模板使用来自父/继承范围的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据其父作用域中的某个变量来选择指令 templateUrl.我不能使用 templateUrl 函数,因为它还没有作用域.我可以从链接函数内部 $templateCache 编译模板(注意它已经存在,我没有加载它),但我担心它会对性能产生负面影响(假设这是一个表格单元指令.. 并且有相当多的单元格).

I want to chose directives templateUrl depending on some variable from its parent scope. I can't use templateUrl function, since it doesn't have a scope yet. I can $compile the template from $templateCache(note that it's already there, I'm not loading it) from inside the linking function, but I am afraid it's gonna have a negative impact on performance(let say this is a table cell directive.. and there's quite a few cells).

我还有其他更好的选择吗?

Do I have any other, better option?

推荐答案

确实别无他法.虽然你应该$compile这种方式来达到比较满意的性能结果.https://stackoverflow.com/a/22646392/301596

There is indeed no other way around. Although you should $compile this way to achieve somewhat satisfactory performance results. https://stackoverflow.com/a/22646392/301596

这篇关于Angular.js 指令模板使用来自父/继承范围的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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