Michael Phelps
Michael Phelps

Reputation: 3591

How get response from resolve property in routeProvider?

My example

 app.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/list', {
        template: '<b>{{status}}</b><input type="button" ng-click="run()" value="click">',
        controller: 'MyCtrl',


        resolve: {
            myVar: function ($http) {

                    return ($http.get('1.php')).then(function (response) {

                        //debugger 
                        var hash = response.data.b
                      return hash;
                    });
                }
             }  


    });

How get property myVar in current scope when i call run? When there is access to this variable ?

Thank you fo your help...

Upvotes: 0

Views: 75

Answers (1)

sma
sma

Reputation: 9597

The name of the resolve property will be injected into your controller by the router. So, in your case, your controller can accept a dependency of 'myVar':

function MyController(myVar) {

}

And myVar will equal whatever the deferred resolves to.

Upvotes: 2

Related Questions