I am using Angular ui-select. My model & ui-select option array are different. While changing value its not updated and not displaying options. I am storing the selected object Id in “pmpo”, I want to show the selected object from the pmptnk object array when loading. But is not working. Some one tell what I am doing wrong.
My object from Model
JavaScript
x
6
1
pmpo:877
2
pmptnk:[0:
3
632:{id: "632", pid: "2993", ESID: "9154", lb1: "Undddd", lb2: "219"}
4
877:{id: "877", pid: "2993", ESID: "9154", lb1: "Pcddd", lb2: "29"}
5
654:{id: "654", pid: "2993", ESID: "9154", lb1: "kukuu", lb2: "246"}]
6
In view file
JavaScript
1
16
16
1
<div ng-if="item.pmptnk.length > 0">
2
<ui-select ng-model="item.pmpo" click-out-side="closeThis($event)">
3
<ui-select-match placeholder="Select " search-placeholder="Filter Tanks"
4
uib-tooltip="{{item.pmpo > 0 ? $select.selected.lb1 : 'Select Tank'}}" tab-select="true">
5
<span ng-bind="$select.selected.lb1"></span>
6
</ui-select-match>
7
<ui-select-choices repeat="obj.tid as obj in (item.pmptnk[item.pmpo])">
8
<span ng-bind="obj.lb1"></span>
9
</ui-select-choices>
10
<ui-select-no-choice>
11
No results matched "{{$select.search}}"
12
</ui-select-no-choice>
13
</ui-select>
14
15
</div>
16
Advertisement
Answer
I worked on your code.I tried it out in different way. Below is my code snippet:
JavaScript
1
19
19
1
<div ng-if="item.pmptnk.length > 0">
2
<ui-select ng-model="item.selected" click-out-side="closeThis($event)">
3
<ui-select-match
4
placeholder="Select "
5
search-placeholder="Filter Tanks"
6
uib-tooltip="{{item.pmpo > 0 ? $select.selected.lb1 : 'Select Tank'}}"
7
tab-select="true"
8
>
9
<span ng-bind="$select.selected.lb1"></span>
10
</ui-select-match>
11
<ui-select-choices repeat="obj.tid as obj in (item.pmptnk)">
12
<span ng-bind="obj.lb1"></span>
13
</ui-select-choices>
14
<ui-select-no-choice>
15
No results matched "{{$select.search}}"
16
</ui-select-no-choice>
17
</ui-select>
18
</div>
19
and i changed my model as below:
JavaScript
1
14
14
1
$scope.item = {};
2
$scope.item.pmpo = 877;
3
$scope.item.pmptnk = [
4
{ id: "632", pid: "2993", ESID: "9154", lb1: "Undddd", lb2: "219" },
5
{ id: "877", pid: "2993", ESID: "9154", lb1: "Pcddd", lb2: "29" },
6
{ id: "654", pid: "2993", ESID: "9154", lb1: "kukuu", lb2: "246" },
7
];
8
for (var i = 0; i < $scope.item.pmptnk.length; i++) {
9
if ($scope.item.pmptnk[i].id == $scope.item.pmpo) {
10
$scope.item.selected = $scope.item.pmptnk[i].tid;
11
break;
12
}
13
}
14
This worked fine for me.