Marcos Gutierrez Marcos Gutierrez - 1 year ago 68
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;

Answer Source

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;    
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download