node.js - Angular2 通知与路由器导航链接

标签 node.js angular angular2-routing angular2-services

我有一个简单的申请表,提交后会导航到另一个页面。 我想在单击提交按钮时显示成功消息。

下面的代码可以工作,但提交后,它立即重定向到其他页面,该页面仅显示通知一秒钟。 我无法将通知添加到目标页面,因为它有多个入口点。

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/

相关文章:

typescript - 使用 Electron 时,我应该如何为 Angular 2 配置基本 href?

json - node-forever json 配置支持所有选项吗?

javascript - 从函数返回值到变量

angular - 在 Angular 7 中有 2 个独立的表格和分页组件

Angular 和 SVG : how to dynamically load custom components?

angular2-routing - 如何最好地将租户包含在 Angular 2 路由中

angular2-routing - CanLoad 与 CanActivate 的延迟加载

Javascript Date - 如何知道 DST 在给定时区是否有效

javascript 变量到 ejs

java - 迭代 Firebase 对象的 JSON 对象