2013-12-11 51 views
0

根據這個實例 http://plnkr.co/edit/uqSB1gIz6XEmJfC8zHNb?p=preview警告框是不是爲我工作

和我都是這樣認爲的,它不是爲我工作! :(爲什麼?

我,包括我的index.htm以下庫

<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/> 
<script type="text/javascript" src="js/jquery.min.js"></script> 
<script type="text/javascript" src="angular/angular.min.js"></script> 


<!-- <script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script> --> 
<script type="text/javascript" src="bootstrap/js/twitter-bootstrap.min.js"></script>  

<!-- Angular Libraries --> 

<script type="text/javascript" src="angular/angular-route.js"></script> 
<script type="text/javascript" src="angular/angular-local-storage.js"></script> 
<script type="text/javascript" src="angular/ui-bootstrap-tpls-0.7.0.min.js"></script> 
<script type="text/javascript" src="angular/angular-strap.js"></script> 

<!-- App related libraries --> 
<script type="text/javascript" src="js/services/ProductServices.js"></script> 
<script type="text/javascript" src="js/controllers/ProductControllers.js"></script> 
<script type="text/javascript" src="js/controllers/ModalControllers.js"></script> 
<script type="text/javascript" src="js/directives/ProductDirectives.js"></script> 
從我的控制器

然後在那裏我創建模塊我添加$ angular.strap依賴像在例如:

var productApp = angular.module('productApp', ['ngRoute', 'LocalStorageModule', 'ui.bootstrap', '$strap.directives']); 

並且在正在顯示該錯誤我這樣做的視圖:

<notification ng-model="successAlert"></notification> 

從那裏我設置「successAlert」消息的控制器,我只是簡單地增加值是這樣的:

$scope.successAlert = data.response; 

現在首先在控制檯中引發此錯誤,而不甚至感人的事情:

TypeError: Cannot read property 'title' of undefined at Object.fn (http://localhost:8080/RESTFulAngularJS/angular/angular-strap.js:40:35) at f.$digest (http://localhost:8080/RESTFulAngularJS/angular/angular.min.js:99:141) at f.$apply (http://localhost:8080/RESTFulAngularJS/angular/angular.min.js:101:369) at f (http://localhost:8080/RESTFulAngularJS/angular/angular.min.js:67:175) at Q (http://localhost:8080/RESTFulAngularJS/angular/angular.min.js:71:99) at XMLHttpRequest.y.onreadystatechange (http://localhost:8080/RESTFulAngularJS/angular/angular.min.js:72:130)

然後,當我進入觸發警報的功能,引發此:

TypeError: Cannot read property 'type' of undefined 
    at Object.fn (http://localhost:8080/RESTFulAngularJS/angular/angular-strap.js:45:42) 
    at f.$digest (http://localhost:8080/RESTFulAngularJS/angular/angular.min.js:99:141) 
    at f.$apply (http://localhost:8080/RESTFulAngularJS/angular/angular.min.js:101:369) 
    at f (http://localhost:8080/RESTFulAngularJS/angular/angular.min.js:67:175) 
    at Q (http://localhost:8080/RESTFulAngularJS/angular/angular.min.js:71:99) 
    at XMLHttpRequest.y.onreadystatechange (http://localhost:8080/RESTFulAngularJS/angular/angular.min.js:72:130) 

我的圖書館有問題嗎?你們能幫我嗎?不知道什麼是錯的......它的應用與示例中的方式完全相同,即腳本導入的順序相同...:S

回答

2

從您發佈的錯誤消息我猜你的data.response對象未定義,因此您的通知將永遠不會顯示。如果仔細觀察蹲在地板上的示例,消息對象的形式爲:

{ 
    "type": "info", 
    "title": "Success!", 
    "content": "alert directive is working pretty well with 3 sec timeout" 
} 

而且您應該尊重這一點。也許你可以與我們分享這data.response應該是什麼樣子以及如何檢索它。

+0

我正在使用「data.response」,這是從RESTFul服務檢索到的值,是的,它在那裏,我的意思是它不是未定義的,在之前的警報消息中使用它,但我更喜歡這個。數據有這樣的「迴應」:{「這已成功保存」}這就是爲什麼我做data.response – msqar

+0

哦,我想我相信我知道你在說什麼,讓我測試。 – msqar

+0

是的,你是對的:)謝謝隊友! – msqar