是否可以从指令分配视图?
import {Directive} from 'angular2/core';
@Directive({
selector: '[foo]'
})
export class FooDirective {
this.bar:string = "baz";
}
并在组件视图中
<div foo>
bar value should be 'baz': {{bar}}.
</div>
http://plnkr.co/edit/To6hj9CJi1caz2pSF0RP?p=preview
我尝试了许多其他方式,例如结构指令(https://angular.io/docs/ts/latest/guide/structural-directives.html)
简而言之:我的指令应为元素创建新的作用域(如在angular 1.x中)
这应该使用模板变量如
@Directive({
selector: '[foo]',
exportAs: 'foo`
})
export class FooDirective {
this.bar:string = "baz";
}
<div foo #foo="foo">
bar value should be 'baz': {{foo.bar}}.
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句