I am new to Angular 2, I have injected directive in current Component
@Component({
selector: 'select-me',
templateUrl: 'app/template.html',
directives: [BackgroundChange] // I want to access this same instance to make the dynamic changes
})
export class PageComponent {
constructor(private backgroundChange:BackgroundChange) {
// I guess this will create new instance of BackgroundChange
}
}
I want to call methods availabe in BackgroundChange to do some changes dynamically from PageComponent
Directives are standalone and should be used in your HTML template - not injected into your PageComponent... aka Directives are not injectable.
The BackgroundChange directive will have access to the HTML element it is attached to in your template - and should do its manipulating within.
Angular docs: https://angular.io/docs/ts/latest/guide/attribute-directives.html#!#apply-directive
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With