Angular2 指令分配给模板
Angular2 directive assign to template
是否可以从指令分配给视图?
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>
是否可以从指令分配给视图?
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>