2017-09-26 81 views
1

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

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

角JS:

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

你需要在代码中包含'toastr'。说明在这里 - https://github.com/CodeSeven/toastr –

回答

1

您需要包括toastr.js和toastr.css文件..请检查的例子

// 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); 
 
    } 
 
});
<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> 
 
\t \t <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>

请通过http://angular-js.in/angular-toastr/

+0

我已经通过npm安装了toastr。所以是否有必要包括脚本src – SRK

+0

不..但确保这些都包括在内,你需要包括模块并注入它..看看上面的共享链接 – Raghav

+0

我遵循你坚持的方式。但我得到错误说明:角没有定义在** angular-toastr.tpls.js ** – SRK

0

在javascript中:您必须包括相应的toastr.js & 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

+0

我会用这个解决方案已经使用约翰帕帕的烤面包机多次:) – rmjoia

相关问题