【问题标题】:using ng2-toastr {ToastsManager} in Angular6在 Angular6 中使用 ng2-toastr {ToastsManager}
【发布时间】:2018-10-05 06:49:09
【问题描述】:

编译失败。

./node_modules/ng2-toastr/src/toast-manager.js 未找到模块: 错误:无法解析 'rxjs/Subject' '/Users/siva/Desktop/Angular/chatApp/node_modules/ng2-toastr/src'

我在 Angular 6 版本中使用 ng2-toastr。当我运行应用程序时,页面显示上述错误。我导入的所有内容都正确声明

这是代码

import { Component, OnInit , ViewContainerRef } from '@angular/core';
import { AppService } from './../../app.service';
import { Routes, Router } from '@angular/router';
import { ToastsManager } from 'ng2-toastr/ng2-toastr';

@Component({
  selector: 'app-signup',
  templateUrl: './signup.component.html',
  styleUrls: ['./signup.component.css']
})
export class SignupComponent implements OnInit {

  public firstName: any;
  public lastName: any;
  public mobile: any;
  public email: any;
  public password: any;
  public apiKey: any;



  constructor(
    public appService: AppService,
    public router: Router,
    private toastr: ToastsManager,
    vcr: ViewContainerRef
  ) { }

【问题讨论】:

  • 请分享您的实际代码
  • 我遇到了与 ng2-toastr 类似的问题。 ng2-toastr 中似乎没有反映 Angular 6 相关的更改。仍在尝试解决此问题

标签: angular rxjs angular6 toastr


【解决方案1】:

你必须用 ngx-toastr 替换 ng2-toastr

这里介绍了步骤https://www.youtube.com/watch?v=YfSvMzUK8BI

你可以跳过开头,从 7 分钟开始

【讨论】:

    【解决方案2】:

    步骤(假设您使用的是 Angular 6):

    1. ng2-toastr更改为ngx-toastr并将版本设置为8.10.2
    2. 运行npm install下载包
    3. 假设您在 app.scss 或 angular.json 的某处导入 ng2-toastr.min.css,请改为导入:@import '~ngx-toastr/toastr.css';
    4. ToastsManager替换为ToastrService,从ngx-toastr导入:

    import { ToastrService } from 'ngx-toastr';

    1. ToastModule 替换为ToastrModule(很可能您将其导入到app.module.ts 文件中:

    import { ToastrModule } from 'ngx-toastr';

    1. 如果您在代码中的任何位置调用 toastr.setRootViewContainerRef,则可以将其删除,因为不再需要它。

    假设您没有以复杂的方式使用ng2-toastr,希望这应该处理好它。

    如果您仍然遇到问题,请查看Mayeed's answer 中的视频。如果您遇到其他问题,还可以在此页面上获得更多详细信息:https://www.npmjs.com/package/ngx-toastr/v/8.10.2


    来源:Mayeed's answer链接的视频。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-06
      相关资源
      最近更新 更多