Resolve in Angular 1.2.16

49 views
Skip to first unread message

Aiko Kirino

unread,
Apr 22, 2014, 11:51:35 PM4/22/14
to ang...@googlegroups.com
I get an error: Error: $injector:unpr Unknown Provider

Here is my the code

//app.js
.....
$routeProvider.
                when('/', {
                    templateUrl: 'default.html',
                    controller: 'TestCtrl',
                    resolve: TestCtrl.resolve
                }).
                otherwise({redirectTo: '/'});



//controllers.js
var TestCtrl = app.controller('TestCtrl ', ['$scope', 'loadData', function($scope, loadData) {
    $scope.data = loadData;
}]);

TestCtrl.resolve = {
    loadData: function($q, $http) {
        var defer = $q.defer();

        $http.get('/api/data/')
            .success(function(d) {
                defer.resolve(d.data);
            })
            .error(function(d) {
                defer.reject();
            });

        return defer.promise;
    }
}


How to fix this?

Sander Elias

unread,
Apr 23, 2014, 12:17:32 AM4/23/14
to ang...@googlegroups.com

Hi Aiko,

test = app.controller(...) puts a reference to app in the test variable. It does not return the TestCrtl.

Regards
Sander

Aiko Kirino

unread,
Apr 23, 2014, 12:41:08 AM4/23/14
to ang...@googlegroups.com
Oh, thanks.
I want get a delaying of route change until data is loaded. eg like this

среда, 23 апреля 2014 г., 8:17:32 UTC+4 пользователь Sander Elias написал:

Sander Elias

unread,
Apr 23, 2014, 3:52:44 AM4/23/14
to ang...@googlegroups.com

Hi Aiko,

try something like this:

$routeProvider.
                when('/', {
                    templateUrl: 'default.html',
                    controller: 'TestCtrl'
,
                    resolve: {loadData:  $http.get('/api/data/')}
                }).
                otherwise({redirectTo: '/'});

Regards
Sander

Aiko Kirino

unread,
Apr 23, 2014, 2:09:05 PM4/23/14
to ang...@googlegroups.com
I used $ q.defer () with your example and it works :) Thx.

среда, 23 апреля 2014 г., 11:52:44 UTC+4 пользователь Sander Elias написал:
Reply all
Reply to author
Forward
0 new messages