重定向后未显示警报消息

时间:2018-03-08 07:10:23

标签: angular

我使用以下plunkr代码来显示成功/错误/警告消息 从API调用中获取成功/错误/警告消息后

[https://plnkr.co/edit/GmOUPtXYpzaY81qJjbHp?p=preview][1]

工作正常。 但问题是在显示消息后我需要导航到另一条路线。 **导航到另一条路线时警报代码正在执行但警报未显示    警报应显示在新路线的顶部

如何处理它。

我的代码是

EditComponent

//some code is missing
this.roomTypeService.editRoomDetials(this.requestedData, this.editData.id)
     .subscribe(suc => this.editBusinessData(suc),
                err => console.log(err));   
//some code is missing

editBusinessData(data) {

    debugger;
    console.log('init', this.businessData.length);
    console.log(data.data);
    let index;
       index = findIndex(this.businessData,  {
         'id' : +(data.data[0].id)
       });
       this.businessData.splice(index, 1);
      console.log(index);
      console.log('after splice', this.businessData.length);
      this.businessData.push(data.data);
      console.log('after adding updated data', this.businessData.length);
      this.customService.setRoomTypesBusinessData(this.businessData);
      this.openDialogBox();
      this.router.navigate(['/clouds/configurations/roomtype/view']);
  }

  openDialogBox() {
   debugger;
    this.dlgProps1.dlgHeader = 'Success';
    this.dlgProps1.msgTxt = 'Record Updated!!';
    this.dlgProps1.okBtn = true;
    this.dlgProps1.cancelBtn = false;
    this.dlgProps1.msgType = 'success';
    this.dlgProps1.setTime = 3000;
    this.dlgProps.emit(this.dlgProps1);
    // console.log(this.dlgProps1, '(((((((');
    this.dialogAnchor.createDialog(DialogComponent);
  }

1 个答案:

答案 0 :(得分:0)

检查一下,

<强> HTML

<div class="col-lg-12 col-sm-12 col-xs-12 alert alert-success" ng-show="successMessagebool ">
    <strong>{{successMessage }}</strong>

<强> JS

$http.post('/user/userList').then(function (response) {
    $scope.successMessage = "Form submitted successfully";
    $scope.successMessagebool = true;
    $timeout(function () {
        $scope.successMessagebool = false;
         window.location = '/user/userList';
    }, 5000);