Reputation: 3321
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)
Upvotes: 3
Views: 349
Reputation: 657466
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>
Upvotes: 4