有没有一种好方法让AngularJS指令评估作为参数传入的属性?如何评估指令中的属性值?
这里有一个simplified example显示我的问题(我承认你能实现这一行为没有指令):
link: function postLink(scope, element, attrs) {
debugger; // scope.$parent already knows the value of teacher here
scope.sendEmail = function(){
alert(attrs.recipient);
//window.open("mailto:" + attrs.recipient);
}
}
我想指令使用的teacher.email
值(注意,链接功能有正确的值为scope.$parent.teacher
)而不是字符串teacher.email
。
只需用scope.recipient替换attrs.recipient – 2013-03-19 18:26:43