detectChanges variable component

37 views
Skip to first unread message

Raffaella Sinisi

unread,
Nov 13, 2019, 11:11:36 AM11/13/19
to Angular and AngularJS discussion
 var response = this.was.postWizardStart(wi);
      response.subscribe(res => { this.zone.run(() => {
        this.idWizard = res.headers.get('idWizard');
        console.log("OK 200 Server - Idwizard is: " + this.idWizard);
        this.ref.detectChanges();
        this.emitValue();
        this.clientId = this.clientId;
      });
      },
       err  => {
         console.log(err);
        });




constructorprivate refChangeDetectorRef,private zone:NgZone




Hello i have a problem with detect changes after post http: the variable "this.idWizard" is not updated. I used both ngZone and ChangeDetectorRef. Thank you so much

Sander Elias

unread,
Nov 13, 2019, 11:17:39 PM11/13/19
to Angular and AngularJS discussion
Hi Raffaella,

Does it log out the updated data to the console?

Regards
Sander

Raffaella Sinisi

unread,
Nov 14, 2019, 4:06:04 AM11/14/19
to Angular and AngularJS discussion

Raffaella Sinisi

unread,
Nov 16, 2019, 11:57:30 AM11/16/19
to Angular and AngularJS discussion
Hi yes in the console ther's the new value.

Thankyou

Sander Elias

unread,
Nov 16, 2019, 1:54:44 PM11/16/19
to Angular and AngularJS discussion
Ok, so at least the value is arriving in your component.
I would need to see some more code, because what you have shown does not cover the cause of your problem.
Can you explain to me why there is a 'var' keyword there?

Raffaella Sinisi

unread,
Nov 18, 2019, 3:35:04 AM11/18/19
to Angular and AngularJS discussion
this is code:

CHILD : header.component.ts

export class HeaderComponent implements OnInitOnChangesDoCheckAfterViewChecked{

 personIdstring;
 @Output() valueChanged : EventEmitter<any> = new EventEmitter<any>();

 ngOnInit() {
 //PersonId
 console.log('HEADER ngOnInit Person Id from route'this.route.snapshot.params.personId);   
 this.route.paramMap.subscribe(params => {
 console.log(params.get('personId'));
 this.personId = params.get('personId');
  

if (this.personId != null){
 var wi = new WizardDefinition(); 

 wi.WiClient =  Number (this.personId);
 wi.WiUser = '';
 wi.WiOpenDate  =  new  Date();
 wi.WiCloseDate =  new  Date();
 wi.WiKey0;


 console.log("HEADER  ngOnInit Creation Wizard:  OpenDate:  " +  wi.WiOpenDate + "CloseDate" + wi.WiCloseDate + "for id person" + this.personId);
}
 var response = this.was.postWizardStart(wi);
 response.subscribe(res => { this.zone.run(() => {
   this.idWizard = res.headers.get('idWizard');
   console.log("HEADER  ngOnInit OK 200 Server - Idwizard is: " + this.idWizard);
  this.emitValue(this.idWizard);
 });
 },
  err  => {
    console.log(err);
   });
 });

}


emitValue(value){
    console.log("emitvalueToParent" );
    this.valueChanged.emit(this.idWizard);
}

}


Raffaella Sinisi

unread,
Nov 18, 2019, 3:37:29 AM11/18/19
to Angular and AngularJS discussion
this.idWizard is a varibale component


Il giorno lunedì 18 novembre 2019 09:35:04 UTC+1, Raffaella Sinisi ha scritto:
this is code:

CHILD : header.component.ts

export class HeaderComponent implements OnInitOnChangesDoCheckAfterViewChecked{
 
 personIdstring;
 @Output() valueChanged : EventEmitter<any> = new EventEmitter<any>();
 idWizard: string;
Reply all
Reply to author
Forward
0 new messages