Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 9865ee8

Browse files
committed
feat(accordion): add controllerAs support
- Expose the controller to the view via `controllerAs` Closes #4138
1 parent a0e1c91 commit 9865ee8

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/accordion/accordion.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
4545
// and adds an accordion CSS class to itself element.
4646
.directive('accordion', function () {
4747
return {
48-
restrict:'EA',
49-
controller:'AccordionController',
48+
restrict: 'EA',
49+
controller: 'AccordionController',
50+
controllerAs: 'accordion',
5051
transclude: true,
5152
replace: false,
5253
templateUrl: function(element, attrs) {

src/accordion/test/accordion.spec.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,36 @@ describe('accordion', function () {
103103
});
104104

105105
describe('accordion', function () {
106-
var scope, $compile, element;
106+
var scope, $compile, $templateCache, element;
107107

108-
beforeEach(inject(function($rootScope, _$compile_) {
108+
beforeEach(inject(function($rootScope, _$compile_, _$templateCache_) {
109109
scope = $rootScope;
110110
$compile = _$compile_;
111+
$templateCache = _$templateCache_;
111112
}));
112113

113-
it('should allow custom templates', inject(function ($templateCache) {
114+
it('should expose the controller on the view', function () {
115+
$templateCache.put('template/accordion/accordion.html', '<div>{{accordion.text}}</div>');
116+
117+
element = $compile('<accordion></accordion')(scope);
118+
scope.$digest();
119+
120+
var ctrl = element.controller('accordion');
121+
expect(ctrl).toBeDefined();
122+
123+
ctrl.text = 'foo';
124+
scope.$digest();
125+
126+
expect(element.html()).toBe('<div class="ng-binding">foo</div>');
127+
});
128+
129+
it('should allow custom templates', function () {
114130
$templateCache.put('foo/bar.html', '<div>baz</div>');
115131

116132
element = $compile('<accordion template-url="foo/bar.html"></accordion>')(scope);
117133
scope.$digest();
118134
expect(element.html()).toBe('<div>baz</div>');
119-
}));
135+
});
120136
});
121137

122138
describe('accordion-group', function () {

0 commit comments

Comments
 (0)