0
我新的角度2和創建應用程序角2通點擊從路由出口app.component
app.routing.ts
const appRoutes: Routes = [
{path:'', component:HomeComponent},
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
// otherwise redirect to home
{ path: '**', redirectTo: '' }
];
app.component.html
<app-navbar (sideMenuToggleClicked)="handleSideMenuToggle()"></app-navbar>
<div class="container-fluid">
<div class="row">
<div class="col col-sm-2 test-border" *ngIf="sideBarToggle">
<h1>
{{sideBarToggle }}
</h1>
</div>
<div class="col col-10 test-border" [ngClass]="sideBarToggle?'col-10':'col-12'">
<app-alert *ngIf="showAlert"></app-alert>
<router-outlet (showAlert)="handleShowAlert($event)"></router-outlet>
</div>
</div>
</div>
register.component.ts
正如您所看到的,我成功捕獲了作爲組件加載的app-navbar中的單擊。
現在我想創建一個共同的警報通知,當我與
<router-outlet (showAlert)="handleShowAlert($event)"></router-outlet>
試試我是不是能夠捕捉到EventEmitter點擊。
的問題是如何從register.component.html轉移射向app.component.html
http://stackoverflow.com/questions/37662456/angular-2-output-from-router-outlet –
https://github.com/angular/angular/issues/11618 –
我得到它與上述兩個工作鏈接。答案來自於stackoverflow和我們需要在app.module.ts中定義的提供者而不是組件 –