I am trying to build a login page where the login template is replaced with the app+router-outlet.
The HTML:
<div class="contentWrapper" *ngIf="!logedin">
Login html....
</div>
<div *ngIf="logedin">
<div #header></div>
<div class="contentWrapper">
<div #nav></div>
<div class="main">
<router-outlet>
</router-outlet>
</div>
</div>
</div>
The Component
export class AppComponent implements OnInit{
logedin = 0;
constructor(
private _dcl:DynamicComponentLoader,
private _elmRef:ElementRef,
private _httpRest:HttpRest //http calls service
){}
ngOnInit(){}
login(){
var vm = this;
//simulated XHR
setTimeout(()=>{
vm.postLoginSuccess()
})
}
postLoginSuccess(){
var vm = this;
vm.logedin = 1;
setTimeout(()=>{
vm.loadApp()
},0);
}
loadApp(){
this._dcl.loadIntoLocation(Header,this._elmRef,"header");
this._dcl.loadIntoLocation(Navigation,this._elmRef,"nav");
}
}
I am trying to: 1) show a login template 2) on login success update logedin 3) hide login accordingly 4) show app
This results in an error msg:
Could not find variable header
I understand this is happening because the #header is a local variable under the scope of the *ngIf template. I tried to resolve this technique (swaping template using *ngIf and local variables # than using loadIntoLocation) in several ways without success.
The thing is my app frame (meaning navigation + header) is not loaded via the <router-outlet> so i need a conditional way to load the frame components without using routing (since <router-outlet> only renders content in my case), after login returned succesfully.
Help will be much appriciated.