If I have a simple button with a click handler and a custom attribute directive like so:
<button (click)="save()" attributedirective="project saved">Save</button>
And in my attribute directive I'm using the hostlistener decorator to listen to the click event:
@Directive({
selector: `[attributedirective]`
})
export class AuditPusher {
@Input('attributedirective') attributedirective: string = 'Missing message!';
@HostListener('click', ['$event'])
pushAudit() {
console.log('text:'+this.attributedirective.toString());
}
}
Which of my code will fire first? The save() on the click event or the code in my attribute directive? - And: Imagine having two attribute directives. Which of those will fire first? In Angular 1 there was something like directive priorities, how is this done in Angular 2? I find it difficult to find documentation on this.
A directive is a custom HTML element that is used to extend the power of HTML. Angular 2 has the following directives that get called as part of the BrowserModule module. If you view the app.
Components have their own view (HTML and styles). Directives are just "behavior" added to existing elements and components. Component extends Directive . Because of that there can only be one component on a host element, but multiple directives.
What is meant by directives in Angular? Directives are classes that add new behavior or modify the existing behavior to the elements in the template. Basically directives are used to manipulate the DOM, for example adding/removing the element from DOM or changing the appearance of the DOM elements.
As far as I know the order of execution is undefined. You shouldn't depend on a specific order.
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