Skip to content

Commit

Permalink
feat(uiView): add controllerAs config with function
Browse files Browse the repository at this point in the history
need to support function pointers so we can pass them in
  • Loading branch information
seanhess committed Jan 28, 2014
1 parent cf34271 commit 1ee7334
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 1ee7334

Please sign in to comment.