Document ready angular

1

I have the following problem:

app.controller('EOGController', ['$scope', function($scope) {
    $scope.result = "primero";

    angular.element(document).ready(function () {
        loadQuantiles();
    });

    var loadQuantiles = function () {   
        console.log("entro");
        $scope.result = "ultimo";
        console.log("salio");
    }
}]);

index.html

<div class="container" ng-controller="EOGController">
    {{result}}  <!-- <- cuyo valor siempre es primero -->
</div>

Why does not it change from

PS: the console.logs() if they exit correctly in the console

    
asked by sirdaiz 23.11.2016 в 15:14
source

1 answer

1

What happens is that you are interrupting the life cycle of the functions in angular, by using the ready event, so you should not use it that way. At the moment that angular executes the controller is because you can already work with the DOM, in case you need something like this, simply call the function:

$scope.$digest()

to warn angular that the variables on the $ scope have changes, just keep in mind that it is not the right way. Example working in codepen

    
answered by 23.11.2016 / 18:46
source