我有一个简单的申请表,提交后会导航到另一个页面。 我想在单击提交按钮时显示成功消息。
下面的代码可以工作,但提交后,它立即重定向到其他页面,该页面仅显示通知一秒钟。 我无法将通知添加到目标页面,因为它有多个入口点。
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>
`
})
关于node.js - Angular2 通知与路由器导航链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38419665/