【发布时间】:2017-07-16 03:43:40
【问题描述】:
我的模块.ts,
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule,Router } from '@angular/router';
import { AppComponent } from './crud/app.component';
import { Profile } from './profile/profile';
import { Mainapp } from './demo.app';
import { Navbar } from './header/header';
// import {ToasterModule, ToasterService} from 'angular2-toaster';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [ BrowserModule,FormsModule, ReactiveFormsModule ,
RouterModule.forRoot([
{ path: '', component:AppComponent},
{ path: 'login', component:AppComponent},
{ path: 'profile', component:Profile}
]) ],
declarations: [ AppComponent,Mainapp,Navbar,Profile ],
bootstrap: [ Mainapp ]
})
export class AppModule {
}
在这里,我想在每次路线更改时从 main.ts 调用一个函数,我该怎么做。谁能帮助我。谢谢。 我的 mainapp.ts,
export class Mainapp {
showBeforeLogin:any = true;
showAfterLogin:any;
constructor( public router: Router) {
this.changeOfRoutes();
}
changeOfRoutes(){
if(this.router.url === '/'){
this.showAfterLogin = true;
}
}
}
我想在每次路线更改时调用这个 changeofRoutes(),我该怎么做?谁能帮帮我。
【问题讨论】:
-
这是不可取的,你打算用那种方法做什么
标签: angular typescript angular2-routing