angular-service-utilities icon indicating copy to clipboard operation
angular-service-utilities copied to clipboard

Attached promise property not resolved until a refresh is done (using ui-router)

Open ord14737 opened this issue 11 years ago • 0 comments
trafficstars

I am wondering whether ui-router and this lib play well together. It seems my $scope property is not resolved when the controller is first instantiated. I need to refresh the page to see the promised JSON in the view. What am I doing wrong?

Service:

app.factory('TheCart', function($q,CartResource,$serviceScope){

    var $scope = $serviceScope();

    var deferredCart = $scope.$defer('theCart');

    CartResource.retrieveCart(function(cart){


                          deferredCart.resolve(cart[0]);




                      });



    return $scope;

  });

Controller:

app.controller('CartCtrl', function (TheCart,$scope)
{      

    TheCart.$attachProperty('theCart', $scope, 'theCart');
}

View:

<div>
 {{ theCart | json }}
</div>

ord14737 avatar Apr 13 '14 06:04 ord14737