[英]Is there any other way to define Toaster
我是 Angular js 的新手。 我正在嘗試顯示錯誤消息 view toaster()
。 我在谷歌上搜索,但沒有找到正確的結果。 當我點擊cancel()
按鈕時,我會收到一條錯誤消息,說toaster is not defined 。
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):
}
您需要包含 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> <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>
在 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.