Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(ngView): reference resolved locals in scope #13400

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ngRoute/directive/ngView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
41 changes: 41 additions & 0 deletions test/ngRoute/directive/ngViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<div>{{$resolve.name}}</div>'
});
});

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: '<div>{{myResolve.name}}</div>'
});
});

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'});
Expand Down