The document discusses several hidden aspects of Angular components and directives, including:
1. How change detection works in Angular and is triggered by events, timers, and XHR using zone.js.
2. How to explore the Angular source code to understand change detection sequences, lifecycle hooks, and classes like ApplicationRef and ChangeDetectionRef.
3. Other concepts like content projection, attribute directives, and differences between how selectors work for components and directives.
34. for (let view of this._views) {
view.detectChanges();
}
this.applicationRef.tick()
ChangeDetectionRef
CD
CD
CD
CD
CD
CD
CD
CD
CD
CD
CD
this.cdr.detectChanges()
Explore the Source Code
35. for (let view of this._views) {
view.detectChanges();
}
this.applicationRef.tick()
ChangeDetectionRef
CD
CD
CD
CD
CD
CD
CD
CD
CD
CD
CD
Demo with ChangeDetectionRef
Explore the Source Code
39. 1. update bound properties for all child components
2. call OnChanges, OnInit, DoCheck and AfterContentInit
lifecycle hooks on all child components
3. update DOM for the current component
4. run change detection for a child component
5. call ngAfterViewInit lifecycle hook for all child components
Detection Sequence
Sequence is slightly different under Ivy engine
48. Attribute Selector in
Component
VS
1. Supporting Original Attributes
<button ngx-button disabled>{{name}}</button>
<ngx-button ngxDisabled></ngx-button>
49. Attribute Selector in
Component
VS
1. Supporting Original Attributes
<button ngx-button disabled>{{name}}</button>
<ngx-button ngxDisabled></ngx-button> .parent > .child{
height: 200px;
background: gray;
}
2. Keep DOM structure
<div class="parent">
<div class="child" ngx-attribute></div>
</div>