带有路由器导航的 Angular2 通知链接
Angular2 Notifications chaining with router navigate
我有一个简单的申请表,提交后导航到另一个页面。
我想在单击提交按钮时显示一条成功消息。
下面的代码有效,但在提交后,它会立即重定向到其他页面,该页面仅显示一秒钟的通知。
我无法将通知添加到目标页面,因为它有多个入口点。
onSubmit(form) {
this._service.success('Test', 'Test'); // this is from angular2-notificaitons library
this.apartmentService.postRequests(this.data).then(_=>this.router.navigate(['Requests'])); //navigates to requests page which has multiple entry points
this.data = {};
}
知道如何实现吗?
您在哪里注册了 NotificationsService 的提供商。我认为问题在于您没有在应用程序的根目录下注册它。
尝试将 NotificationsService 和 SimpleNotificationsComponent 指令移动到您的 app.component。
@Component({
selector: "app",
directives: [SimpleNotificationsComponent],
providers: [NotificationsService, PushNotificationsService],
template: `
<simple-notifications [options]="options" (onCreate)="onCreate($event)" (onDestroy)="onDestroy($event)">
</simple-notifications>
`
})
我有一个简单的申请表,提交后导航到另一个页面。 我想在单击提交按钮时显示一条成功消息。
下面的代码有效,但在提交后,它会立即重定向到其他页面,该页面仅显示一秒钟的通知。 我无法将通知添加到目标页面,因为它有多个入口点。
onSubmit(form) {
this._service.success('Test', 'Test'); // this is from angular2-notificaitons library
this.apartmentService.postRequests(this.data).then(_=>this.router.navigate(['Requests'])); //navigates to requests page which has multiple entry points
this.data = {};
}
知道如何实现吗?
您在哪里注册了 NotificationsService 的提供商。我认为问题在于您没有在应用程序的根目录下注册它。
尝试将 NotificationsService 和 SimpleNotificationsComponent 指令移动到您的 app.component。
@Component({
selector: "app",
directives: [SimpleNotificationsComponent],
providers: [NotificationsService, PushNotificationsService],
template: `
<simple-notifications [options]="options" (onCreate)="onCreate($event)" (onDestroy)="onDestroy($event)">
</simple-notifications>
`
})