Unsubscribe from Observables and DOM events. Stop interval timers. Unregister all callbacks that this directive registered with global or application services. You risk memory leaks if you neglect to do so.
Here are the pertinent excerpts from that HeroDetailComponent: src/app/hero-detail.component.ts (template) template:`
<div>
<img src="{{heroImageUrl}}">
<span [style.text-decoration]="lineThrough">
{{prefix}} {{hero?.name}}
</span>
<button (click)="delete()">Delete</button>
</div>` src/app/hero-detail.component.ts (deleteRequest) // This component makes a request but it can't actually delete a hero.
deleteRequest =newEventEmitter<Hero>();delete(){this.deleteRequest.emit(this.hero);}
The component defines a deleteRequest property that returns an EventEmitter. When the user clicks delete, the component invokes the delete() method, telling the EventEmitter to emit a Hero object.
Now imagine a hosting parent component that binds to the HeroDetailComponent's deleteRequest event.
<app-hero-detail (deleteRequest)="deleteHero($event)" [hero]="currentHero"></app-hero-detail> When the deleteRequest event fires, Angular calls the parent component's deleteHero method, passing the hero-to-delete (emitted by HeroDetail) in the $event variable.
Angular offers a special two-way data binding syntax for this purpose, [(x)]. The [(x)] syntax combines the brackets of property binding, [x], with the parentheses of event binding, (x).
The import statement specifies an additional ElementRef symbol from the Angular core library:
You use the ElementRef in the directive's constructor to inject a reference to the host DOM element, the element to which you applied appHighlight.
ElementRef grants direct access to the host DOM element through its nativeElement property.
This first implementation sets the background color of the host element to yellow.
@HostListener The @HostListener decorator lets you subscribe to events of the DOM element that hosts an attribute directive, the <p> in this case.
Of course you could reach into the DOM with standard JavaScript and attach event listeners manually. There are at least three problems with that approach:
1.You have to write the listeners correctly.
2.The code must detach the listener when the directive is destroyed to avoid memory leaks.
3.Talking to DOM API directly isn't a best practice.
At a high level, there are basically three types of data structures. Stacks and Queues are array-like structures that differ only in how items are inserted and removed. Linked Lists , Trees , and Graphs are structures with nodes that keep references to other nodes. Hash Tables depend on hash functions to save and locate data. In terms of complexity , Stacks and Queues are the simplest and can be constructed from Linked Lists . Trees and Graphs are the most complex because they extend the concept of a linked list. Hash Tables need to utilize these data structures to perform reliably. In terms of efficiency , Linked Lists are most optimal for recording and storing of data, while Hash Tables are most performant for searching ...
Behavior of git checkout Checking out an earlier commit will change the state of at least one file. This is sometimes true . Git doesn't allow you to save a new commit if no files have been updated, so you might think this is always true. However, it's possible to do the following: Save a commit (call this commit 1). Update some files and save another commit (call this commit 2). Change all the files back to their state during commit 1, then save again (call this commit 3). This sometimes happens if commit 2 contained a bug, and it's important to fix the bug quickly. The easiest thing to do might be to remove all the changes introduced by commit 2 to fix the bug, then figure out how to safely reintroduce the changes later. At this point, commit 3 is the latest commit, so if you checkout commit 1, none of the files will be changed. Checking out an earlier commit will change the state of more than one file. Checking out an earlier commit will change the sta...