我想知道是否可能有这样的东西:
div ng-repeat="(k,v) in items" <div ng-if="k == 'a' or k == 'b'"> <!-- SOME CONTENT --> </div>
知道项目是通过请求接收的JSON容器,所以这就是为什么我使用一个键值方法。
谢谢
我问,因为我已经尝试谷歌搜索,但唯一的结果,我可以得到与ng开关,但我必须使用ng-if。
你当然可以。就像是:
原文链接:https://www.f2er.com/angularjs/147003.htmlHTML
<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'];
演示Fiddle