Event Emitter not call parent function

35 views
Skip to first unread message

Raffaella Sinisi

unread,
Nov 20, 2019, 8:27:56 AM11/20/19
to Angular and AngularJS discussion
import { ANALYZE_FOR_ENTRY_COMPONENTSComponent,AfterViewCheckedOnInitChangeDetectorRefInputOutputEventEmitterAfterViewInitNgZoneChangeDetectionStrategyViewChildOnChangesSimpleChangeSimpleChangesDoCheckAfterContentCheckedAfterContentInit } from '@angular/core';

import {DomSanitizerfrom '@angular/platform-browser';
import {MatIconRegistryMatSelectChangefrom '@angular/material';
import {ReponseServicefrom '../question/ReponseService';


import {WizardDefinitionUserAccessfrom '../models/PrjdeVie';


import {FormControlReactiveFormsModulefrom '@angular/forms';

import {Observablefrom 'rxjs';
import {map,startWithfrom 'rxjs/operators';


import { ActivatedRouteParamMap } from '@angular/router';
import { AppComponent } from '../app.component';



export class Client{

  constructor(public idClientnumber){}
}


export class Data{

idwizardstring;


constructor(public idClientnumber){}

}

@Component({
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.css'],
  providers: [
    ReponseService]
})
export class HeaderComponent implements OnInit,OnChanges

//,OnChanges, DoCheck, AfterViewChecked, AfterContentInit, AfterContentChecked

{
  searchCtrl : FormControl;
  hideSearchCtrlboolean;
 
  userstring;
  wizardKeynumber;


 idWizardstring;

  personIdstring;


 @Output() valueChanged = new EventEmitter();

 
  idWizardNumber : number;

  //Gestione dei clienti
  listClientsUserAccess [] = [];
  clientsClient[] = [];
  filteredClientsObservable<any[]>;
  clientIdnumber;
  public clientnumber;


  emitflag : boolean;


  ngOnChanges(changesSimpleChanges){

    for (let propName in changes) {  
      let change = changes[propName];
      let curVal  = JSON.stringify(change.currentValue);
      let prevVal = JSON.stringify(change.previousValue);
    
            console.log(curVal"+++++");
            console.log(prevVal + "++++");
         }
  }
  

  constructorprivate refChangeDetectorRef,private zone:NgZone ,private routeActivatedRoute,iconRegistryMatIconRegistrysanitazerDomSanitizerprivate was:ReponseServicepublic cdChangeDetectorRef) {
    this.emitflag = false;

    this.hideSearchCtrl = true;
    this.searchCtrl = new FormControl();
    //console.log(this.clientId + " Initial value of clientId");
    this.filteredClients = new Observable<any[]>();

    //list of client 
    // this.filteredClients = this.searchCtrl.valueChanges.pipe(
      //startWith(''),
      //map(client => client ? this.filterClients(client.toString()): this.clients.slice())
    //);


    iconRegistry.addSvgIcon('logo-PG'sanitazer.bypassSecurityTrustResourceUrl('assets/brand-logo-brown.svg'));

    //this.user = "test";
    console.log("HEADER COMPONENT User Login: " + was.getUser().subscribe(
       data => 
       { 
         console.log(data);
         this.user = data;
         //console.log("user" + data);
         console.log("HEADER COMPONENT User Login after subscribe: " + this.user);
        } )
        );





        this.route.paramMap.subscribe(params => {
          //console.log(params.get('personId'));
          this.personId = params.get('personId');
          console.log("ngOnInit: " + this.personId);
        });
    
    
    
        if (this.personId !== null){
    
          console.log("ngOnInit 1" + this.personId);
    
          var wi = new WizardDefinition();
         
          wi.WiClient =  Number (this.personId);
          wi.WiUser = '';
          wi.WiOpenDate  =  new  Date();
          wi.WiCloseDate =  new  Date();
          wi.WiKey0;
    
          console.log("Creation Wizard:  OpenDate:  " +  wi.WiOpenDate + "CloseDate" + wi.WiCloseDate);
         
          if(wi !== null){
    
            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.idWizard = res.headers.get('idWizard');
            console.log("HEADER  ngOnInit 2 OK 200 Server - Idwizard is: " + this.idWizard);
            // this.ref.markForCheck()
             
             console.log(this.idWizard + " +++" + res.headers.get('idWizard') ) ;
             this.valueChanged.emit(this.idWizard);  
             this.ngAfterContentChecked();
                  
            },
             err  => {
               console.log(err);
              });
           }
          }    

}





  ngOnInit() {

    // this.route.paramMap.subscribe(params => {
    //   //console.log(params.get('personId'));
    //   this.personId = params.get('personId');
    //   console.log("ngOnInit: " + this.personId);
    // });



    // if (this.personId !== null){

    //   console.log("ngOnInit 1" + this.personId);

    //   var wi = new WizardDefinition();
     
    //   wi.WiClient =  Number (this.personId);
    //   wi.WiUser = '';
    //   wi.WiOpenDate  =  new  Date();
    //   wi.WiCloseDate =  new  Date();
    //   wi.WiKey= 0;

    //   console.log("Creation Wizard:  OpenDate:  " +  wi.WiOpenDate + "CloseDate" + wi.WiCloseDate);
     
    //   if(wi !== null){

    //     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.idWizard = res.headers.get('idWizard');
    //     console.log("HEADER  ngOnInit 2 OK 200 Server - Idwizard is: " + this.idWizard);
    //     // this.ref.markForCheck()
         
    //      console.log(this.idWizard + " +++" + res.headers.get('idWizard') ) ;
    //      this.valueChanged.emit(this.idWizard);  
    //      this.ngAfterContentChecked();
              
    //     },
    //      err  => {
    //        console.log(err);
    //       });
    //    }
      
    
    //   // this.emitValue("0000000000000");
    // }



//      //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');
//  //console.log("HEADER  ngOnInit HEADER COMPONENT personId: " + this.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.WiKey= 0;
// }

// if(wi !== null){
//   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);
//    console.log("AFTER emit value to parent" + this.idWizard);
//    this.emitValue(this.idWizard);this.emitValue(this.idWizard);this.emitValue(this.idWizard);this.emitValue(this.idWizard);this.emitValue(this.idWizard);this.emitValue(this.idWizard);

//  });
//  },
//   err  => {
//     console.log(err);
//    });
// }
// console.log("AFTER emit value to parent 22" + this.idWizard);
// this.emitValue(this.idWizard);this.emitValue(this.idWizard);this.emitValue(this.idWizard);this.emitValue(this.idWizard);this.emitValue(this.idWizard);
//  });

   
  //   if (this.personId != null){
  //     //this.emitValue(this.idWizard);
  //     //
  //   }
  //   else
  //   {

  //   // //console.log("Value of client" + this.clientId);
  //     this.searchCtrl.valueChanges.subscribe(val => {
  //     //console.log("New research, value of client code"  + val);
  //     if (val != 0){
  //       this.clientId = val;
  //     }
     
  //     console.log("New research, value of clientId attribute"  + val);

  //     console.log("getListCodeClients");
  //     this.filteredClients = new Observable<any[]>();
  //      console.log("User Login into getListCodeClients: " + this.was.getUser().subscribe(
  //       data => 
  //       { 
  //         console.log(data);
  //         this.user = data;
          
  //        } )
  //        );
  
  //     try{
  //       this.was.getClientsByUser(this.user.substring(2, this.user.length), this.clientId.toString()).subscribe(clientList => {
  //         this.clients = [];
  //         clientList.forEach(element => 
  //         {
  //         console.log("PersonId " + element.personId);
  //         this.clients.push(new Client(Number (element.personId)));
  //         });
         
  //         this.filteredClients = this.searchCtrl.valueChanges.pipe(
  //           startWith(''),
  //           map(client => client ? this.filterClients(client.toString()): this.clients.slice())
  //         );
      
  //         });
  //     }
  //     catch(e){
  //       console.log(e);
  //     }


  //   }
  //  );
  // }

//   setInterval( ()=>{

// if((Number(this.idWizard))> 0){
//     this.emitValue(this.idWizard);
//     //this.valueChanged.emit(this.idWizard);
//   this.ref.detectChanges();
//   this.ref.markForCheck();
//   console.log(this.idWizard + "setInterval");
// }
//     },3000
//   );

  
  }

  openSearch(){

   /* if (this.hideSearchCtrl == true)
        this.hideSearchCtrl = false;
    else*/
    this.hideSearchCtrl = false;
  }



  filterClients(idClientstring){
      //call get client
      return this.clients.filter(client => client.idClient.toString().indexOf(idClient.toLocaleLowerCase()) === 0);
  }

  updateIdClient(clientIDanyeventMatSelectChange){
    this.clientId = Number(clientID);
    

    console.log("Client ...: " + this.clientId);

    console.log("Client ...: " + this.clientId);

    console.log("Client ...: " + this.clientId);

    


    // //this.getListCodeClients();

    //  //get user
     console.log("User Login into getListCodeClients: " + this.was.getUser().subscribe(
      data => 
      { 
        console.log(data);
        this.user = data;
        //console.log("user" + data);
        //console.log("User Login ng oninit: " + this.user);
       } )
       );


  
    console.log("idclient into header" + this.clientId);
    console.log("event" + event.source.selected);

     if (event.source.selected && this.personId == null){
      var wi = new WizardDefinition(); 
    
     wi.WiClient =  Number (this.clientId);
     wi.WiUser = this.user;
     wi.WiOpenDate  =  new  Date();
     wi.WiCloseDate =  new  Date();
     wi.WiKey0;
   
     console.log("Creation Wizard:  OpenDate:  " +  wi.WiOpenDate + "CloseDate" + wi.WiCloseDate);
     var response = this.was.postWizardStart(wi);
     response.subscribe(res => {
       this.idWizard = res.headers.get('idWizard');
       console.log("OK 200 Server - Idwizard is: " + this.idWizard);
        this.valueChanged.emit(this.idWizard);
        this.clientId = clientID.toString();
     },
      err  => {
        console.log(err);
       });
     }
    this.hideSearchCtrl = true;
  }

 
  emitValue(value:string){

    // setInterval( ()=>{

    //   if((Number(value))> 0){
    //     this.valueChanged.emit(value);
    //     console.log("emitvalueToParent WIZARD ID" + value);
       
    //   }
    //       },15000
    //     );


   
  }


  emitValue2(){
    this.ref.detectChanges();
    this.ref.markForCheck();
   this.valueChanged.emit(this.idWizard);
   console.log("------------------------------->" + "  " + this.idWizard);


  }


    ngDoCheck(){
      //setInterval( ()=>{

        // if((Number(this.idWizard))> 0){
        //   this.valueChanged.emit(this.idWizard);
        // console.log("ngdoCheck" + this.idWizard);
        //   //this.ngDoCheck();
        // }
           // },15000
         // );    
  }


//    ngAfterContentInit(){
//     this.ref.markForCheck();
    
//     if(this.emitflag)
//          {
//         console.log(" ngAfterContentInit: START " + "  " + this.idWizard);
//         this.valueChanged.emit(this.idWizard);
//         }
//     console.log(" ngAfterContentInit: END ");
//    }


   ngAfterContentChecked(){

    if(Number(this.idWizard)> 0){
     console.log("ngAfterContentChecked      this id " + this.idWizard);
     this.valueChanged.emit(this.idWizard);
    }

   }


//    ngAfterViewInit(){
//     this.ref.markForCheck()
//     if(this.emitflag)
//     {
//    console.log("  ngAfterViewInit: START " + "  " + this.idWizard);
//    this.valueChanged.emit(this.idWizard);
//    }
// console.log("  ngAfterViewInit: END ");
//    }

//    ngAfterViewChecked(){
//     if(this.emitflag)
//     {
//    console.log(" ngAfterViewChecked: START " + "  " + this.idWizard);
//    this.valueChanged.emit(this.idWizard);
//    }
// console.log(" ngAfterViewChecked: END ");
//     }


}


header.component.ts
Reply all
Reply to author
Forward
0 new messages