THE SITUATION:
I am making an angular app where I have to use ui-select: in the user info page, in the select have to be possible to choose one or many tag. It is almost working, except from the fact that i have problems to get and display the pre-existent tags.
THE CODE:
View:
<ui-select multiple ng-model="info_data.tags" theme="bootstrap" ng-disabled="disabled">
<ui-select-match placeholder="Select tag...">{{$item.name}} </ui-select-match>
<ui-select-choices repeat="tag in all_tags | propsFilter: {name: $select.search}">
{{tag.name}}
</ui-select-choices>
</ui-select>
<p>Selected: {{info_data.tags}}</p>
Controller:
$http({
url: base_url + 'main/db_get_all_tags',
method: "POST",
}).success(function (data) {
$scope.all_tags = data;
});
$scope.show_info = function() {
var result_info = DbService.get_info( $stateParams.db_data_id );
result_info.then( function( data )
{
$scope.info_data = data;
});
};
ATTEMPT 1:
It happens a very strange behavior. I don't see the tags in the info page of the user, and not even in the ui-select. Except if refresh 5/6 times, then suddenly it will magically work, displaying the tags in the user info page and in the ui-select. In both cases, working and not, i get several error message of the same kind:
Cannot read property 'length' of undefined.
ATTEMPT 2:
In order to resolve this problem, I have added this code in the controller:
$scope.info_data = { tags: [] };
$scope. all_tags = [];
And i don't get anymore any error message. The app is stable and i can see the proper tags in the user info page. The only problem is that the tags are not loaded anymore in the ui-select.
If i select a new tag then it works fine, but i loose the pre-existing tags.
QUESTION(s):
How can i make ui-select properly working? (currently v0.8.3) There is a problem of conflict?
How can i properly call pre-existent data from the server?
Thank you very much!
propsFilter
is a custom method. That potentially saved me hours of head-scratching. I'm going to submit a PR to ui-select that states as much. – Liberec