Web Developer

Angular Issues

1. Could not find module “@angular-devkit/build-angular”

     Answer: npm install; ng update; npm update

2. If you try to access CSS selectors in Angular, sometime these selectors are encapsulated, you can use: “:host ::ng-deep selector name” or “:host /deep/ selector name” to access it. (https://angular.io/guide/component-styles#deprecated-deep–and-ng-deep)

3. @ViewChild() is always available in ngAfterViewInit (lifecycle). That is why in Angular Material Table Sorting, you have to put datasource.sort  = sort in ngAfterViewInit but not ngOnInit where @ViewChild() is still not available. 

    (useful link:  https://blog.angular-university.io/angular-viewchild/)

4. Angular Material Table Sorting: 

     a: import MatSortModue into NgModule

     b: if the mat table in *ngIf structure directive, the sorting will not working. you can use “hidden” directive to hide the container. (https://stackoverflow.com/questions/46893164/mat-table-sorting-demo-not-working)

     c: @ViewChild() should put in ngAfterViewInit() but not ngOnInit(). However, if the datasource come from Observable, it can be put in ngOnInit(), because this is an event (event stack), which will be executed after heap statement finished (event loop).

Leave a Reply

Your email address will not be published. Required fields are marked *.

*
*
You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>