diff --git a/src/ngRoute/directive/ngView.js b/src/ngRoute/directive/ngView.js index f26ffbb3df5e..efb291392793 100644 --- a/src/ngRoute/directive/ngView.js +++ b/src/ngRoute/directive/ngView.js @@ -275,6 +275,7 @@ function ngViewFillContentFactory($compile, $controller, $route) { $element.data('$ngControllerController', controller); $element.children().data('$ngControllerController', controller); } + scope[current.resolveAs || '$resolve'] = locals; link(scope); } diff --git a/test/ngRoute/directive/ngViewSpec.js b/test/ngRoute/directive/ngViewSpec.js index 39ab1a934fea..bb5a64951fa7 100644 --- a/test/ngRoute/directive/ngViewSpec.js +++ b/test/ngRoute/directive/ngViewSpec.js @@ -120,6 +120,47 @@ describe('ngView', function() { }); + it('should reference resolved locals in scope', function() { + module(function($routeProvider) { + $routeProvider.when('/foo', { + resolve: { + name: function() { + return 'shahar'; + } + }, + template: '
{{$resolve.name}}
' + }); + }); + + inject(function($location, $rootScope) { + $location.path('/foo'); + $rootScope.$digest(); + expect(element.text()).toEqual('shahar'); + }); + }); + + + it('should allow to provide an alias for resolved locals using resolveAs', function() { + module(function($routeProvider) { + $routeProvider.when('/foo', { + resolveAs: 'myResolve', + resolve: { + name: function() { + return 'shahar'; + } + }, + template: '
{{myResolve.name}}
' + }); + }); + + inject(function($location, $rootScope) { + $location.path('/foo'); + $rootScope.$digest(); + expect(element.text()).toEqual('shahar'); + }); + }); + + it('should load content via xhr when route changes', function() { module(function($routeProvider) { $routeProvider.when('/foo', {templateUrl: 'myUrl1'});