烤面包机未在 angular4 中触发

Toaster is not triggering in angular4

我已经通过使用这个 link -> http://www.codershood.info/2017/04/14/showing-notification-using-toaster-angular-2/

在我的 angular 4 项目中实现了烤面包机

当我通过单击按钮触发它时,它工作得非常好

我添加了一个按钮,例如

<div class="btn btn-success" (click)="showSuccess()">Success Notification</div>

我添加了以下功能

public showSuccess(){    
      this.toastr.success("Success", 'You are on right track.');
  }

它工作得非常好,但是当我尝试按照以下方式调用它时,它不起作用:

编辑:添加了完整的组件代码

import { Component, OnInit,ViewContainerRef } from '@angular/core';
import { FormsModule }   from '@angular/forms';
import {Router} from '@angular/router';
import { AuthService } from '../services/auth.service';
import { Constants } from '../../constants';
import { ToastsManager } from 'ng2-toastr/ng2-toastr';
import { EmployeeComponent } from '../employee/employee.component';





@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})

export class LoginComponent implements OnInit {

     title = 'GGMD ';
   invalidLogin: boolean;

  constructor(
    private router: Router,
    private authService: AuthService,
    public toastr: ToastsManager, 
    public _vcr: ViewContainerRef) {
    this.toastr.setRootViewContainerRef(_vcr);
  } 

  ngOnInit() {
  }
public showSuccess(){    
      this.toastr.success("Success", 'You are on right track.');
  }

    signIn(credentials){

        let response = this.authService.logIn(credentials);
        if(response.AuthenticationStatus === true){

          switch(response.Role){

               case 'employee':
                this.router.navigate(['/employee']);
                this.toastr.success("Success", 'You are on right track.');
                console.log("Success", 'You are on right track.');
                break;

              case 'manager':
                this.router.navigate(['/manager']);
                console.log('I am manager');
                break;

              default:
                console.log( error);
        }
      }
    }

日志正常工作并且导航成功,但烤面包机不工作。 我也尝试过传递函数,例如

 this.router.navigate(['/employee']);
                this.showSuccess()
                console.log("Success", 'You are on right track.');

这将不起作用,因为您已经更改了根 this.router.navigate(['/employee']);

尝试将 toast 代码放在 this.router.navigate(['/employee']); 之类的东西之前

      this.toastr.success("Success", 'You are on right track.');
      this.router.navigate(['/employee']);

我不确定上面是否可行其他解决方案是您可以在员工组件构造函数中显示敬酒