angular
*ngIf condition is not fired/doesn't update template in ngOnChanges
I have a child a component that does not fire the condition for *ngIf child component: export class child { #Input() user; #Input() list; listLength: number; showBtn: boolean = false; constructor(){} ngOnChanges(changes: SimpleChanges){ this.userId = this.user.id; this.userList = this.list; this.listLength = this.userList.length; // this updates everytime when changes happen on another component thats pushed from this component. if (this.listLength > 3){ // this doesn't fire until I refresh the page this.showBtn = true; }
You probably also get an error output in the browsers console. Invoke change detection explicitly if you update the model in ngOnChanges() constructor(private cdRef:ChangeDetectorRef){} ngOnChanges(changes: SimpleChanges){ this.userId = this.user.id; this.userList = this.list; this.listLength = this.userList.length; // this updates everytime when changes happen on another component thats pushed from this component. if (this.listLength > 3){ // this doesn't fire until I refresh the page this.showBtn = true; } this.cdRef.detectChanges(); } }
Related Links
AOT Compilation error in angular library
Angular, Ionic2 Configure #ViewChild every time it is initialized
Angular ViewContainerRef and its ViewRefs - dynamic versus declarative?
Setting one parameter to a certain value upon entering a different parameter - NgSwitch?
Angular 2 page transition while leaving page
Adding the Multiselect feature to an Angular4 dropdown?
Add lines of code depending on folder structure - Precompiler?
Angular2 Rxjs Observable catch method compilation error
Partial file loader for translations [on hold]
How to pass data from modal to component?
Angular code diference between source code and debugger code
Angular2 cannot use the values of a subscribe in another subscribe (observable)
Angular 2 Passing parameters to the template through #Input() [closed]
All declarations of 'size' , 'prototype' must have identical modifiers
Accessing the Device Camera without getUserMedia [closed]
Template Error on ngFor and using pipe with parameter