使用角带库的警报框对我来说不起作用

时间:2013-12-11 18:18:28

标签: javascript angularjs twitter-bootstrap angular-strap

按照这个例子 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>

然后从我正在创建模块的Controller中添加$ angular.strap依赖项,如下例所示:

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

在显示错误的视图中,我这样做:

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

在我设置“successAlert”消息的控制器中,我只是添加一个这样的值:

$scope.successAlert = data.response;

现在首先,在控制台中抛出此错误,甚至没有触及任何内容:

  

TypeError:无法读取未定义的属性“title”       在Object.fn(http://localhost:8080/RESTFulAngularJS/angular/angular-strap.js:40:35)       在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)       在f(http://localhost:8080/RESTFulAngularJS/angular/angular.min.js:67:175)       在Q(http://localhost:8080/RESTFulAngularJS/angular/angular.min.js:71:99)       在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

1 个答案:

答案 0 :(得分:2)

从您发布的错误消息中我猜测您的data.response对象未定义,因此您的通知将永远不会显示。如果仔细查看plunker中的示例,则消息对象的格式为:

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

你应该尊重这一点。也许您可以与我们分享这个data.response应该是什么样子以及如何检索它。