Skip to content

Commit

Permalink
Merge pull request angular-ui#808 from seanhess/master
Browse files Browse the repository at this point in the history
added support for controllerAs with function variables instead of string
  • Loading branch information
nateabele committed Jan 28, 2014
2 parents cf34271 + 1ee7334 commit f17b587
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/viewDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ function $ViewDirective( $state, $compile, $controller, $injector, $ui
if (locals.$$controller) {
locals.$scope = currentScope;
var controller = $controller(locals.$$controller, locals);
if ($state.$current.controllerAs) {
currentScope[$state.$current.controllerAs] = controller;
}
currentEl.children().data('$ngControllerController', controller);
}

Expand Down
18 changes: 17 additions & 1 deletion test/viewDirectiveSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ describe('uiView', function () {
},
jState = {
template: '<span ng-class="test">jState</span>'
},
kState = {
controller: function() {
this.someProperty = "value"
},
controllerAs: "vm",
};

beforeEach(module(function ($stateProvider) {
Expand All @@ -90,7 +96,8 @@ describe('uiView', function () {
.state('g', gState)
.state('g.h', hState)
.state('i', iState)
.state('j', jState);
.state('j', jState)
.state('k', kState)
}));

beforeEach(inject(function ($rootScope, _$compile_) {
Expand Down Expand Up @@ -307,6 +314,15 @@ describe('uiView', function () {

expect($uiViewScroll).toHaveBeenCalledWith(target);
}));

it('should instantiate a controller with controllerAs', inject(function($state, $q) {
elem.append($compile('<div><ui-view>{{vm.someProperty}}</ui-view></div>')(scope));
$state.transitionTo(kState);
$q.flush();
var innerScope = scope.$$childHead
expect(innerScope.vm).not.toBeUndefined()
expect(innerScope.vm.someProperty).toBe("value")
}))
});

});

0 comments on commit f17b587

Please sign in to comment.