Sunday, 30 April 2017

Angular.js geting data from mongodb

I have a problem with getting request in my api from Angular.js. After i loged in to my app I keep the username in $rootScope.currentuser,

        $rootScope.$on('$routeChangeStart', function () {
        if (Auth.isLoggedIn()) {
            app.isLoggedIn = true;
            Auth.getUser().then(function (data) {
                $rootScope.currentuser = data.data.username;
                app.username = data.data.username;
                app.useremail = data.data.email;
                app.loadme = true;
            });
        } else {
            app.isLoggedIn = false;
            app.username = '';
            $rootScope.currentuser = '';
            app.loadme = true;
        }
    });

then I call the middleware:

    $http.get('/api/costs/' + $rootScope.currentuser).then(function (data) {
        $scope.costs = data.data;
    });

to get specific costs for current user, unfortunetelly this get request doesn't work, I checked $rootScope.currentuser right after login and this value is assigned properly. What is curious, when I manualy assigned in user name middleware

        $http.get('/api/costs/' + 'test').then(function (data) {
        $scope.costs = data.data;
    });

the date is populated.



via Bogusław Boczkowski

No comments:

Post a Comment