Using angular ui-select. Documentation u-i angular selection
In a select input you want to show the names of the ports.
<li class="col-xs-12 col-sm-6">
<div class="form-group">
<label>Port</label>
<ui-select ng-model="shipmentObject.portArray" theme="bootstrap" style="width:auto;">
<ui-select-match>{{$select.selected.shipmentObject.portArray}}</ui-select-match>
<ui-select-choices repeat="item in shipmentObject.portArray | filter: $select.search">
<div ng-bind-html="item.portName | highlight: $select.search"></div>
<!-- <small ng-bind-html="item.code | highlight: $select.search"></small> -->
</ui-select-choices>
</ui-select>
</div>
{{item.portName}}
</li>
The backend information is brought
OptimaResource.getPort(country).then(function(resp){
// this.portCode=[];
$scope.shipmentObject.ports = resp.data;
// console.log($scope.shipmentObject.ports);
var array = resp.data;
var resultado = array.map(function(elemento)
{
var dividir = elemento.split("|");
return {portCode: dividir[0], portName: dividir[1]};
});
$scope.shipmentObject.portArray = resultado;
// console.log($scope.shipmentObject.portArray);
// // console.log($scope.shipmentObject.ports);
// console.log(angular.toJson($scope.shipmentObject.portArray));
console.log($scope.shipmentObject.portArray);
console.log($scope.shipmentObject.portArray.data);
// $scope.shipmentObject.portJson = angular.toJson($scope.shipmentObject.portArray);
// console.log($scope.shipmentObject.portJson);
// console.log($scope.shipmentObject.portJson);
});
When selecting a port, it is not selected in the input and throws the following error
Expected array but received: {"portCode": "0106", "portName": "HOULTON", "$$ hashKey": "object: 1266"}
And this throws the documentation on this kind of error
Description This error occurs when the filter is not used with an array:
<input ng-model="search">
{{key}}: {{value}}