Marcos Gutierrez Marcos Gutierrez - 3 months ago 8
AngularJS Question

From factory to $scope . What is the right way?

I would like to know which is the correct way to initialize a variable with the data of a factory. Currently I do it this way, but does not convince me . I'm wrong? I 'm using Angular.

$scope.result = [];
$scope.result = data;


A factory (singleton) is a service that aims to provide variables and/or methods.

in your controller:


MyFactory.var1 = $scope.var1;
$scope.resultOfSomethingDone = MyFactory.doSomething();

And if implements promises (asynchronously, return values (or exceptions) when they are done processing.) :

    $scope.dataResult = data;