1
我在$scope
內部有一個對象數組。該對象具有name
和attributes
是其中一個對象的'attributes'屬性。我有一個文本字段,我需要將其綁定到應該用於過濾基於name
或noOfCitizens
的狀態的模型。但是,下面的代碼不會過濾這些項目。我哪裏出錯了。數組內對象屬性的角度過濾器
我與Angularjs工作1.5.8版本
//Inside the controller
$scope.states=[];
var mp = {};
mp.name = "MP";
mp.attributes= {
"name":"MP",
"noOfCitizens":"~ 900000"
};
var ts = {};
ts.name = "TS";
ts.attributes= {
"name":"TS",
"noOfCitizens":"~ 8000"
};
$scope.states.push(mp);
$scope.states.push(ts);
<!-- Inside my html page -->
<div style="margin-left: 10px">
<input type="text" ng-model="state.attributes['name']" placeholder="filter">
</div>
<div class="col-lg-3" ng-repeat="state in states | filter:state.attributes['name']">
<h2>{{state.name}}</h2>
<ul>
<li>Name: {{state.attributes['name']}}</li>
<li>No Of Citizens: {{state.attributes['noOfCitizens']}}</li>
</ul>
</div>