2013-07-31 130 views
0

我想知道是否有方法为指令中的变量设置模板路径? 我有一种这样的代码:指令变量中的AngularJS模板

tooltip = "<img src={{object.avatar}}>" + {{object.fullname}} 

而且我想在模板文件/像tooltip.html.haml并设置在我的模板。所以我可以在我的指示:

tooltip = "../templates/tooltip.html.haml" 

或其他路径如果有必要。

可能吗?

我的指令的结束:

linker = (scope, element, attrs) -> 
    element.html(tooltip).show() 
    $compile(element.contents()) scope 

restrict: "E" 
replace: true 
scope: 
    object: "=" 
link: linker 

由于通过提前

回答

0

指令对象的使用模板或templateUrl参数

linker = (scope, element, attrs) -> 
element.html(tooltip).show() 
$compile(element.contents()) scope 

restrict: "E" 
templateUrl: "tooltip.html" // or 
template: "<img src='{{object.avatar}}'>" 
replace: true 
scope: 
object: "=" 

链接:链接

+0

我object.avatar是显示得不错,我有从bdd获得的好路径。但我想把所有这些代码放在一个模板中,使其具有可读块的html文件。 – guillaumek

+0

@guillaumek哦,我弄错了,使用'template'或'templateUrl'参数的指令(查看这里,长版http://docs.angularjs.org/guide/directive) – vittore

+0

是的,我现在明白了,感谢您的帮助 – guillaumek