Adding spinner or searching
Is there on option to display a spinner or "Searching..." text till the refresh method finished? I'm loading the data remotely and it can take 2-3 seconds till I get the data.
I guess you have to handle this by yourself. I also load the data via ajax (ok takes only 400 to 800 ms) but i also want to show the spinner as indicator for the user that something is happen.
Maybe not the best coding style but i am new in angular.
Example:
<div class="input-group">
<div ng-show="loadUsers" class="loading-indicator"></div>
<ui-select ng-model="userDefault.selected" theme="bootstrap">
<ui-select-match placeholder="{f:translate(key: 'backend.recordlog.filter.placeholder.users')}">{{$select.selected.name}}</ui-select-match>
<ui-select-choices refresh="fetchUsers($select.search)" refresh-delay="300" repeat="user in users | orderBy:'name' | filter:$select.search">
<div ng-bind-html="user.name | highlight: $select.search"></div>
<small ng-bind-html="user.email | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
<span class="input-group-btn">
<button ng-click="resetToDefault()" class="btn btn-default">
<span class="glyphicon glyphicon-remove"></span>
</button>
</span>
</div>
And the related javascript code used in my directive:
function fetchUsersBySearchTerm(searchTerm) {
var parameters = {'searchTerm': searchTerm};
$scope.loadUsers = true;
AjaxService.users(parameters).then(
function(payload) {
var users = payload.data;
UserService.setUsers(users);
$scope.users = convertObjectToArray(users);
$scope.loadUsers = false;
}
);
}
@markusguenther Tip: if your AjaxService is using ngResource you should definitely look at the $resolved property of the return value
Actually i only use $http. But i have heard of ngRessource and will try it anytime :) Thanks for the hint.
I need this functionality as well. I need it to go one step further as well. I'm using a remote data source to ajax in search results. I need a way to display what amounts to a "no records found" message when the search returns no results.
---Update--- I "solved" this by extending the uiSelectChoices directive.
@MBentley1976 can you provide an example? Thinking this should be included in base.
Any updates?
Heres my solution....
/**
* Get Data products...will be Injected into products
*/
$scope.products = [];
$scope.isProductFound = false;
$scope.getProducts = function(search) {
if(!search) return;
$scope.isProductLoaded = true; //for loading info when a search for product is conducted
var params = {search: search, warehouse_id : $scope.warehouse.selectedWarehouseId};
return $http.get(SITE_URL + 'transaction/getProducts', {params: params} ).then(function(response) {
$scope.products = response.data.data
if (response.data.data.length < 1) {
$scope.isProductFound = true;
} else {
$scope.isProductFound = false;
}
$scope.isProductLoaded = false;
});
};
<div class="input-group">
<ui-select name="product" ng-model="product.no_int_product" on-select=onSelectProduct($item) theme="bootstrap" reset-search-input="true" style="width:500px">
<ui-select-match placeholder="Search product by Name, Code..">{{$select.selected.product_name}}</ui-select-match>
<ui-select-choices repeat="product.no_int_product as product in products"
refresh="getProducts($select.search)"
refresh-delay="500" style="width:500px">
<div ng-bind-html="product.product_name"></div>
</ui-select-choices>
</ui-select>
<!-- Show only when loading... -->
<span class="input-group-addon" ng-show="isProductLoaded && !isProductFound" style="background: none;border:none"><i class="fa fa-spinner fa-pulse"></i></span>
<!-- Show only If product not found -->
<span class="input-group-addon" style="background: none;border:none" ng-show="isProductFound">Not found...</span>
</div>
FWIW I think this is now here: https://github.com/angular-ui/ui-select/pull/1779
Closing as resolved by #1779