I am trying to make that when I give click
to checkbox
an expression is executed when it has finished bringing the datos
of the function getUsers()
, apparently it works fine.
But then what I want to do is to deactivate or disable the checkbox
until it has not finished loading the first call to the request. That is, they can not give more click
until they have brought the data , records .
PS: If you have a service that takes a long time 30 seconds or more, then deactivate the checkbox
or some other way to avoid giving click
to the checkbox
var app = angular.module('App', ['ngMaterial', 'ngMessages']);
app.controller('AppCtrl', function($scope, $timeout, $q, $http) {
$scope.getUsers = function() {
return $q(function(resolve,reject) {
$http.get('https://jsonplaceholder.typicode.com/users').then(function(res) {
$scope.users = res.data;
resolve();
});
});
};
$scope.filterUsers = function() {
setTimeout(function() {
$scope.getUsers().then(function() {
console.log("Termino de traer los datos");
});
});
}
$scope.getUsers();
});
<!DOCTYPE html>
<html ng-app="App">
<head>
<link rel="stylesheet" href="https://rawgit.com/angular/bower-material/master/angular-material.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular-animate.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular-aria.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular-messages.js"></script>
<script src="https://rawgit.com/angular/bower-material/master/angular-material.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="AppCtrl">
<div flex="30" layout="row" layout-align="end center">
<md-checkbox class="md-color-blue" style="margin: 0;" ng-model="filterUser" ng-click="filterUsers()" aria-label="user filter">
Filtrar usuarios
</md-checkbox>
</div>
</body>
</html>