Angularjs 终端:正确且优先>;“100个原因”@&引用;停止工作的参数
下面的代码“中断”插值范围值Angularjs 终端:正确且优先>;“100个原因”@&引用;停止工作的参数,angularjs,angularjs-directive,Angularjs,Angularjs Directive,下面的代码“中断”插值范围值p1:“@”。是我做错了什么,还是这是一只角虫 .directive("foo", function($compile){ return { terminal: true, priority: 200, // anything > 100 templateUrl: "foo.html", scope: { p1: "@", // doesn't work p2: "=", // works
p1:“@”
。是我做错了什么,还是这是一只角虫
.directive("foo", function($compile){
return {
terminal: true,
priority: 200, // anything > 100
templateUrl: "foo.html",
scope: {
p1: "@", // doesn't work
p2: "=", // works
p3: "&" // works
},
link: function(scope, element){
// this also doesn't help
$compile(element.contents())(scope);
}
};
});
模板foo.html
是:
<div>{{p1}}</div>
<div>{{p2}}</div>
{{name}}
something
问题在于您在指令上设置的优先级。 通常,只有在一个元素上有多个指令时,优先级才相关。优先级决定了这些指令的应用/启动顺序。在大多数情况下,您不需要优先级,但有时在使用编译函数时,您希望确保先运行编译函数 现在您的问题是您已经设置了 指令as 200。其中,{{}}插值的优先级为 100. 因此,在本例中,即使在插值值之前,指令也会编译,因此p1属性的值为{{something} 保持指令的优先权,任何小于100的事情 一切都会如期进行
是的,但是为什么手动调用
$compile
没有帮助呢?啊,我想我只是去做了。变量p1
被分配了一个字符串“{{name}}”
。你很快就得到了,准确地说不到1分钟:D