Angular 烤面包机未按角度4触发

Angular 烤面包机未按角度4触发,angular,angular-toastr,Angular,Angular Toastr,我已经通过使用此链接在angular 4项目中实现了toaster-> 当我通过点击按钮触发它时,它工作得非常好 我加了一个按钮 <div class="btn btn-success" (click)="showSuccess()">Success Notification</div> 它工作得非常好,但当我试着像下面这样称呼它时,它就不工作了: 编辑:添加完整的组件代码 import { Component, OnInit,ViewContainerRef } fr

我已经通过使用此链接在angular 4项目中实现了toaster->

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

我加了一个按钮

<div class="btn btn-success" (click)="showSuccess()">Success Notification</div>
它工作得非常好,但当我试着像下面这样称呼它时,它就不工作了:

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

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);
        }
      }
    }
日志正在工作并成功导航,但toaster不工作。 我还尝试了传递函数,例如

 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']);

我不确定上述方法是否有效其他解决方案是您可以在employees组件构造函数中显示toast

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

尝试将toast代码放在this.router.navigate(['/employee'])之前类似于

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

我不确定上述方法是否有效。其他解决方案是,您可以在调试时在employees组件构造函数中显示toast。你的断点命中了吗?你能分享你的typescript组件的完整代码吗?@Metehan Senol我现在已经在你调试时编辑了我的问题。你的断点命中了吗?你能分享你的typescript组件的完整代码吗?@Metehan Senol我现在已经编辑了我的问题如果控制通过了,那么为什么console.log可以工作,我也尝试过这样做,但它也不起作用。@MikiJay这意味着你必须在employees组件构造函数中展示你的吐司,而不是在控制通过了之后为什么console.log可以工作,我也尝试过这种方法,但它也不能工作。@MikiJay这意味着您必须在employees组件构造函数中展示您的toast