Coder Social home page Coder Social logo

Comments (8)

cgross avatar cgross commented on May 27, 2024

In the Angular docs for $resource, look for $promise

https://docs.angularjs.org/api/ngResource/service/$resource

from angular-busy.

sgentile avatar sgentile commented on May 27, 2024

ok thanks

from angular-busy.

doodirock avatar doodirock commented on May 27, 2024

@cgross

Still a bit confused by this. If I have a service like below:

.factory('hiMom', function($resource) {
    return $resource('/api/v1/stuff.json?showing=:showing',
    {showing: '@showing'},
    {'query':  {method:'GET', isArray:false}});
})

and Im running a query in my controller with something simple like:

.controller('StuffS', function ($scope, hiMom) {
    hiMom.query({ showing: 'all'}, function(data){
        $scope.result = data;
    });
})

Couldn't i then just access the promise with

$scope.myPromise = hiMom.query();

from angular-busy.

cgross avatar cgross commented on May 27, 2024

Resources don't return the promise from a query method. In the docs it talks about a $promise.

$scope.myPromise = hiMom.query().$promise;

The instance methods on the resources do return promises directly.

from angular-busy.

doodirock avatar doodirock commented on May 27, 2024

@cgross Thanks so much for the fast response. I should have really read a bit deeper before I typed all that out. I now have my call looking like this:

.controller('StuffS', function ($scope, hiMom) {
    hiMom.query({ showing: 'all'}, function(data){
        $scope.result = data;
        $scope.myPromise = data.$promise;
    });
})

However even though it seems to be accessing the promise the directive stays hidden when the page loads. Not sure what I'm missing here.

from angular-busy.

cgross avatar cgross commented on May 27, 2024

The promise is attached to the return code from query(), not to the data in the callback.

from angular-busy.

doodirock avatar doodirock commented on May 27, 2024

I started with the below code with no luck and figured it was supposed to be in the data callback.

$scope.myPromise = hiMom.query().$promise;

Seems like the directive picks it up but no annimation triggers

from angular-busy.

doodirock avatar doodirock commented on May 27, 2024

Figured it out @cgross. Thanks so much for the help! Silly mistakes on my part.

from angular-busy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.