I have this code
@Component({
selector: 'unb-navbar',
templateUrl: './navbar.html'
})
export class NavbarComponent implements OnInit {
@Input() brand: string;
controlador:boolean=false;
overlay:string="";
@Input() menus:any = [{
name: 'Início',
icon: 'home',
router: 'home',
path:'home'
}];
private html: string ='';
constructor(private http: Http, private router: Router, private authenticationService: AuthenticationService, private navbarService: NavbarService){
}
ngOnInit() {
//this.carregarMenuDinamico();
}
carregarMenuDinamico(){
this.authenticationService.getUrlFromBarramento()
.subscribe(res=> {
this.navbarService.createTemplate (AuthenticationService.base_url)
.subscribe (res => {
this.html = res;
});
},
error => {
this.authenticationService.getUrlFromConfig()
.subscribe(response =>{
this.navbarService.createTemplate (AuthenticationService.base_url)
.subscribe (res => {
this.html = res;
});
});
});
}
carregarBars(){
if(this.controlador){
this.controlador =false;
this.overlay = "none";
}else{
this.controlador =true;
this.overlay = "block";
}
}
}
When this line is execute this.html = res; the this.html is undefined always, and I don't know why.
The code compile correctly with webpack and this method run without erros but never atribute any value to this.html is ever undefined.
I try to put a console.log but this happen:
this thing apears in debug in chrome
But this thing appen when coneols.log this variables
use console.log in res and this.html
But nothing change in . And i don't know why.
this.html = res;, and it displays something, and if you addconsole.log(this.html)right after that line of code, it prints undefined? I find it hard to believe. Please do that, and tell what is printed. I.e. replacethis.html = res;byconsole.log('res = ' + res); this.html = res; console.log('html = ' + this.html);.