烤箱没有触发角度4

时间:2017-11-08 07:38:06

标签: angular angular-toastr

我已经通过使用此链接在我的角度4项目中实现了烤面包机 - > http://www.codershood.info/2017/04/14/showing-notification-using-toaster-angular-2/

当我通过点击按钮

触发它时,它正常工作

我添加了一个按钮,例如

arrival_guest

我添加了以下功能

<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);
        }
      }
    }

1 个答案:

答案 0 :(得分:0)

由于您更改了根this.router.navigate(['/employee']);

,因此无效

尝试在this.router.navigate(['/employee']);之前添加Toast代码

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

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