2017-09-26 40 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

相關問題