I am working on an application of Angular 6 with the step of parameters through the use of a service.
In the constructor method I call the following service (app.component.ts):
constructor(private userService: UserService) {
      this.menuService.getDataRegister(this.aliasUser)
      .subscribe(
        data => {
          if(data == 1) {
            this.userService.setPage(1);
            this.page = this.userService.getPage();
            console.log('page1: ', this.page);
          } else {
            this.userService.setPage(0);
            this.page = this.userService.getPage();
          }
        }, // Bind to view
        error => {
          // Log errors if any
          this.processError(error);
        });
        console.log('page2: ', this.page);
    }
  }
The value of console.log "page1" shows me the expected content, but the value of console.log "page2", I get undefined and the value should remain, because it is same variable and load it in the answer ok of the service.
And then when I try to pick it up in another component, it loads undefined too (home.component.ts):
this.page = this.userService.getPage();
console.log('page: ', this.page);
What could be the problem? thanks,
 
     
    