AngularJS NG-如果与多个条件 [英] AngularJS ng-if with multiple conditions
本文介绍了AngularJS NG-如果与多个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有可能有这样的事情:
I'd like to know if it's possible to have something like this:
div ng-repeat="(k,v) in items"
<div ng-if="k == 'a' or k == 'b'">
<!-- SOME CONTENT -->
</div>
明知是项目通过请求获得一个JSON的容器,所以这就是为什么我使用的键,值的方法。
Knowing that items is a JSON container received through a request, so that's why I'm using a key, value method.
感谢
我问,因为我已经试过Google上搜寻它,但唯一的结果我能得到用NG-开关,但我有NG-如果使用。
I'm asking because I've tried googling it, but the only result I could get were with ng-switch, but I have to use ng-if.
推荐答案
当然可以。是这样的:
HTML
<div ng-controller="fessCntrl">
<label ng-repeat="(key,val) in list">
<input type="radio" name="localityTypeRadio" ng-model="$parent.localityTypeRadio" ng-value="key" />{{key}}
<div ng-if="key == 'City' || key == 'County'">
<pre>City or County !!! {{$parent.localityTypeRadio}}</pre>
</div>
<div ng-if="key == 'Town'">
<pre>Town!!! {{$parent.localityTypeRadio}}</pre>
</div>
</label>
</div>
JS
var fessmodule = angular.module('myModule', []);
fessmodule.controller('fessCntrl', function ($scope) {
$scope.list = {
City: [{name: "cityA"}, {name: "cityB"}],
County: [{ name: "countyA"}, {name: "countyB"}],
Town: [{ name: "townA"}, {name: "townB"}]
};
$scope.localityTypeRadio = 'City';
});
fessmodule.$inject = ['$scope'];
演示<大骨节病> 小提琴 骨节病>
这篇关于AngularJS NG-如果与多个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文