3

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.