Is it possible to assign to view from directive?
import {Directive} from 'angular2/core';
@Directive({
selector: '[foo]'
})
export class FooDirective {
this.bar:string = "baz";
}
And in component's view
<div foo>
bar value should be 'baz': {{bar}}.
</div>
http://plnkr.co/edit/To6hj9CJi1caz2pSF0RP?p=preview
I have tried many other ways like structural directives ( https://angular.io/docs/ts/latest/guide/structural-directives.html )
In short: my directive should create new scope for element (like in angular 1.x)
This should work using a template variable like
@Directive({
selector: '[foo]',
exportAs: 'foo`
})
export class FooDirective {
this.bar:string = "baz";
}
<div foo #foo="foo">
bar value should be 'baz': {{foo.bar}}.
</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.