简体   繁体   English

在AngularJS警报上显示ng-show

[英]ng-show on AngularJS alert

I am trying to display some alerts with AngularJS, see http://angular-ui.github.io/bootstrap/ - alert section. 我试图用AngularJS显示一些警报,请参阅http://angular-ui.github.io/bootstrap/ - alert部分。 I want to modify the example to show only the alerts that have a "show" attribute set to true: 我想修改示例以仅显示“show”属性设置为true的警报:

  $scope.alerts = [
    { type: 'error', msg: 'Oh snap! Change a few things up and try submitting again.', show: true }, 
    { type: 'success', msg: 'Well done! You successfully read this important alert message.', show: false }
  ];

In the alert tag I have added ng-show="alert.show" , but it seems it does not display any alert. 在警报标签中,我添加了ng-show="alert.show" ,但它似乎没有显示任何警报。 You can find the code here: http://plnkr.co/edit/Qbv4A9u1SnQeJy9o81lK?p=preview . 你可以在这里找到代码: http//plnkr.co/edit/Qbv4A9u1SnQeJy9o81lK?p = preview

What have I done wrong? 我做错了什么? Thanks in advance! 提前致谢!

Move ng-repeat and ng-show to a parent div. ng-repeatng-show到父div。

<div ng-controller="AlertDemoCtrl">
  <div ng-repeat="alert in alerts" ng-show="alert.show">
    <alert type="alert.type" close="closeAlert($index)">{{alert.msg}}</alert>
  </div>
  <button class='btn' ng-click="addAlert()">Add Alert</button>
</div>

ng-show is a directive by itself which I am skeptical is not working in hand with alert directive from UI Bootstrap. ng-show本身就是一个指令,我怀疑它与UI Bootstrap的alert指令没有合作。

Modified Plunker 改良的Plunker

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM