有没有其他方法来定义Toaster

时间:2017-09-26 10:34:58

标签: javascript angularjs

我是Angular js的新手。我正在尝试显示错误消息视图toaster()。我在谷歌搜索,但我没有找到正确的结果。当我点击cancel()按钮时,我会收到一条错误消息,指出烤面包机未定义

Html:<button class="btn btn-secondary" ng-show="editMode" ng-click="toggle_cancel()"> Cancel </button>

Angular Js:

 $scope.toggle_erase = function(information){
      toastr.toggle_erase('Are you sure want to delete ?')
       $scope.hideDelay(3000):
}

2 个答案:

答案 0 :(得分:1)

您需要包含toastr.js和toastr.css文件..请查看示例

&#13;
&#13;
// Code goes here

var app = angular.module('myapp',['toastr']);

app.controller('demo',function($scope,toastr){
  $scope.toggle_remove = function(){
    toastr.info('Hello!!');
    toastr.refreshTimer(toastr, 3000);
  }
});
&#13;
    <link rel="stylesheet" href="style.css">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
    <script src="https://npmcdn.com/angular-toastr/dist/angular-toastr.tpls.js"></script>
		<link rel="stylesheet" href="https://npmcdn.com/angular-toastr/dist/angular-toastr.css" />
    <script src="script.js"></script>
  </head>

  <div ng-app="myapp">
    <div class="container" ng-controller="demo">
      <button class="btn btn-secodary" ng-hide="editMode" ng-click="toggle_remove()"> Delete </button> <br/>
  </div>
  </div>
&#13;
&#13;
&#13;

请浏览http://angular-js.in/angular-toastr/

答案 1 :(得分:0)

在javascript中:您必须包含各自 toastr.js&amp;项目中的toastr.css 文件

   //cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js
   //cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css

然后使用如下:

$.ajax({
        url: url
        type: "POST",
        data: data,
        async: false,
        success: function(response) {
        toastr.success('your success msg');
        }
        error : function(response){
        toastr.error('your error msg');
        }

       });

有关详细信息,请参阅以下链接:https://github.com/CodeSeven/toastr