Using ngDreamFactory module: Getting error “TypeError: Cannot read property 'login' of undefined”

Hi,

I am trying to to loggin using the ngDreamFactory angular module but I getting a “TypeError: Cannot read property ‘login’ of undefined”.

I use
AngularJS - Version 1.2.24
angular-dreamfactory - Version ??? (Current)

Controller:

module.controller('AppCtrl', function ($scope, $log, DreamFactory, ApartmentService, APP_CONFIG) {
    $scope.creds = {
        email: 'APP_CONFIG.userName',
        password: 'APP_CONFIG.password'
    };

    $scope.apartments = [];
    $scope.getApartments = function () {
        ApartmentService.getAll().then(
            function (result) {
                $scope.apartments = result;
            },
            function (reject) {
                console.error('reject')
            });
    };

    // Error: 
    DreamFactory.api.user.login($scope.creds,
        function (data) {
            console.info('Login success');
            $scope.getApartments();
        },
        function (error) {
            console.info('Login failed')
        }
    );
});

Any idea ?

It doesn’t appear the module was able to pull your API.
No other errors in the console?

Hi, I’m having the same problem, I’m just getting into DreamFactory and trying to get the Trivia App example to work, using the free cloud DSP and have followed the instructions precisely. My JS console error is:

TypeError: undefined is not a function
    at _formatAndCreateJsonObj (http://0.0.0.0:9000/scripts/services/services.js:221:29)
    at http://0.0.0.0:9000/scripts/services/services.js:248:30
    at wrappedCallback (http://0.0.0.0:9000/bower_components/angular/angular.js:11561:81)
    at http://0.0.0.0:9000/bower_components/angular/angular.js:11647:26
    at Scope.$eval (http://0.0.0.0:9000/bower_components/angular/angular.js:12673:28)
    at Scope.$digest (http://0.0.0.0:9000/bower_components/angular/angular.js:12485:31)
    at Scope.$apply (http://0.0.0.0:9000/bower_components/angular/angular.js:12777:24)
    at done (http://0.0.0.0:9000/bower_components/angular/angular.js:8371:45)
    at completeRequest (http://0.0.0.0:9000/bower_components/angular/angular.js:8585:7)
    at XMLHttpRequest.xhr.onreadystatechange (http://0.0.0.0:9000/bower_components/angular/angular.js:8524:11) undefined angular.js:10061

When I try to make a single call to the movies API like this:

$scope.testvar=DreamFactory.api.movies.getMovie({q:"Scarface"});

I get the following error:

TypeError: Cannot read property 'getMovie' of undefined
    at new <anonymous> (http://0.0.0.0:9000/scripts/controllers/main.js:37:51)
    at invoke (http://0.0.0.0:9000/bower_components/angular/angular.js:3966:17)
    at Object.instantiate (http://0.0.0.0:9000/bower_components/angular/angular.js:3977:23)
    at http://0.0.0.0:9000/bower_components/angular/angular.js:7274:28
    at link (http://0.0.0.0:9000/bower_components/angular-route/angular-route.js:911:26)
    at nodeLinkFn (http://0.0.0.0:9000/bower_components/angular/angular.js:6704:13)
    at compositeLinkFn (http://0.0.0.0:9000/bower_components/angular/angular.js:6098:13)
    at publicLinkFn (http://0.0.0.0:9000/bower_components/angular/angular.js:5994:30)
    at boundTranscludeFn (http://0.0.0.0:9000/bower_components/angular/angular.js:6118:21)
    at controllersBoundTransclude (http://0.0.0.0:9000/bower_components/angular/angular.js:6725:18) <div data-ng-view="" class="ng-scope"> 

Hope you can help!
Thanks

Most certainly. When your app loads, do you see the requests for /rest/api_docs/{resource} all coming back with 200 OK?

db, files, email come back 200 OK,
movies?q=Charly GET comes back 200,
movies?q=Charly OPTIONS comes back 204 no content

Cheers for the fast reply!

Sorry, wasn’t checking the whole list, basically all the standard api’s come back 200 OK, OPTIONS calls come back 204.

Options are fine as long as the request eventually passes pre-flight and GETs the url, which appears is fine here.

Are you using a hosted DSP or running a bitnami install? Just so I can tell what version we’re testing.

I’m using the free hosted DSP at cloud.dreamfactory.com

Ok, let me try and reproduce with a new cloud instance.
Can you send me your DSP name so I can peak at your config?

https://dsp-appintment.cloud.dreamfactory.com

Cheers!

Config looks good. Can you assign one app to the role you have set for guest users, and let me know the app name for it? I’ll try and pull your api docs.

The guest users have the role “Trivia Users”, and this role is assigned to the app “trivia”. The Live API Doc all works fine from the Launchpad. Ah! I just now pressed “Update” on the Trivia Users role, and now there are no assignments under Service Access and System Access. I’ll add that stuff and see if that fixes it.

EDIT: Nope, the access was there, it just reverted to an empty role when I pressed update.

Yeah it went back to Create mode.

I’m running the Angular SDK against your machine and can make calls to the db , so its definitely built, let me modify my code to use the app name you gave me.

It looks like your service config has getMovies defined, not getMovie , try changing that.

getMovie is the name of the function in the Trivia App Services code, but this in turn calls DreamFactory.api.movies.getMovies({“q”: _generateSearchTerm()}, so I think the naming should be all right?

EDIT: I see your point, I can try a direct call using getMovies…

I pulled your services down, and by changing the name in the app to getMovies, the request fired successfully.

[The image you are requesting does not exist or is no longer available]

Was that done with angular-dreamfactory (or indeed the sample angular Trivia app)? I tried adding the line:

$scope.testvar=DreamFactory.api.movies.getMovies({'q':'Scarface'});

inside the controller, and this gives the error

TypeError: Cannot read property 'getMovies' of undefined

I might just be not understanding things with the angular-dreamfactory module, but it seems like DreamFactory.api.movies returns something undefined.

Good point, let me grab that codebase instead of just writing my own test with angular-dreamfactory.

Furthermore, I now noticed from the console that I’m actually getting a valid response from a movies query (Rocky, to be precise), but it’s still returning this error so there’s something fishy with the angular code.

Ah, I see now that I didn’t quite understand how to use the library, I shouldn’t call it like

$scope.testvar=DreamFactory.api.movies.getMovies({'q':'Scarface'});

, instead I should have a callback function for success/failure. But this doesn’t explain why things aren’t working with the original unmodified app.