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

Categories

HOME
excel
arduino
junit
refactoring
soap
sendmail
mono
microsoft-cognitive
g2o
powerbuilder
metal
animate.css
aws-codepipeline
android-animation
glusterfs
xhtml
formula
spf
sapply
restcomm
fix
trackjs
twitter-typeahead
atlassian-sourcetree
licode
android-constraintlayout
pyside
cloudify
intercept
code-injection
ssis-2008
indexoutofrangeexception
eof
http-caching
hibernate-criteria
hal
data-migration
spacing
radius
servicestack.redis
post-build-event
street-address
package-name
tablet
swiftmailer
database-theory
smartassembly
watchdog
silent-installer
graylog
crypto++
local-variables
jwrapper
review-board
metamodel
tizen-sdb
dotpeek
google-roads-api
ntfs-3g
ng-template
http-accept-header
frontpage
rebase
lg
ooyala
cirqus
custom-taxonomy
delphi-5
undefined-symbol
xcode-bots
offsetheight
acronym
kermit
circular-buffer
android-view
irssi
avaloq-script
class-relationship
mysql-error-1093
unassigned-variable
n-tier
teamcity-7.1
pyro
maptiler
graphml
kendo-tooltip
circular-reference
uipicker
batoo
dynamic-languages
emacs-dirtree
iphone-4
contentflow
generic-list
xemacs
twisted.internet
ext-direct
wind-river-workbench
log5j
statusnet
css-parsing
context-sensitive-help
visual-programming
mkstorekit
comdlg32
resource-cleanup

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile