我需要将一个值绑定到 ui-select ng-model
UI-SELECT 显示带有来自 JSON 响应的图标的类别
<ui-select ng-model="trans.cat" >
<ui-select-match placeholder="Select a categorie...">
<img ng-src="{{$select.selected.caticon}}" class="icons"/>
{{$select.selected.catname}}
</ui-select-match>
<ui-select-choices repeat=" cat in categorie | filter: $select.search">
<img ng-src="{{cat.caticon}}" class="icons"/>{{cat.catname}}
</ui-select-choices>
我的类别响应是这样的:
{"Categorie":[{"catname":"Taxi","caticon":"img/ic_taxi.png","catvalue":1,"_id":"59eb8faa0a0c7534403cbd0a","__v":0}]
我需要将 catvalue 绑定到 ng 模型,我尝试了很多解决方案,但我不断得到 [对象对象] 或未定义的结果。
我的 GET 请求 :
$scope.categorie = [];
$http.get('http://localhost:3000/api/cat', {withCredentials: true}).success(function(data) {
$scope.categorie = data.Categorie;
});
我认为你需要这个,
<ui-select-choices repeat="cat in categorie.Categorie">
<img ng-src="{{cat.caticon}}" class="icons"/>
<div ng-bind="val.catname "></div>
</ui-select-cfhoices>
演示