twitter-bootstrap AngularJS 警报上的 ng-show
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19405693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ng-show on AngularJS alert
提问by Tenzi
I am trying to display some alerts with AngularJS, see http://angular-ui.github.io/bootstrap/- alert section. I want to modify the example to show only the alerts that have a "show" attribute set to true:
我正在尝试使用 AngularJS 显示一些警报,请参阅http://angular-ui.github.io/bootstrap/- 警报部分。我想修改示例以仅显示将“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.
You can find the code here: http://plnkr.co/edit/Qbv4A9u1SnQeJy9o81lK?p=preview.
在我添加的警报标签中ng-show="alert.show",但它似乎没有显示任何警报。您可以在此处找到代码:http: //plnkr.co/edit/Qbv4A9u1SnQeJy9o81lK?p=preview。
What have I done wrong? Thanks in advance!
我做错了什么?提前致谢!
回答by dmahapatro
Move ng-repeatand ng-showto a parent div.
移动ng-repeat和ng-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-showis a directive by itself which I am skeptical is not working in hand with alertdirective from UI Bootstrap.
ng-show本身就是一个指令,我怀疑它是否与alertUI Bootstrap 的指令不兼容。

