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.
SDLC - Software Development Life Cycle is a process used by the software industry to design, develop and test high quality softwares. 1- Requirement Analysis 2- Defining Requirements To clearly define and document the product requirements SRS (Software Requirement Specification) document which consists of all the product requirements to be designed and developed during the project life cycle. 3- Designing the Product Architecture One design approach for the product architecture is proposed and documented in a DDS - Design Document Specification . DDS is reviewed by all the important stakeholders and based on various parameters as risk assessment, product robustness, design modularity, budget and time constraints, the best design approach is selected for the product. DDS defines all the architectural modules of the product along with its communication and data flow representation with the external and third party modules. 4- Developing the ...
Padding and Margin padding and layout_margin are two very similar attributes. Both determine the space around a View. The difference is that padding determines space within the boundaries of the view, and layout_margin determines the space outside the boundaries of the view. Width and Height Some of the most important properties are the width property and height property - those must be defined for every view. Remember that all views occupy a rectangular area on the screen - the width and height are the width and height of that area. You can define this in pixels, or better yet dp (stands for density-independent pixels): android:layout_width="200dp" android:layout_height="300dp" For the sake of having a layout be responsive and adjust to different devices, two common values are not numbers at all, but wrap_content and match_parent used as shown here: android:layout_width="wrap_content" android:layout_height="ma...