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

Commit

Permalink
feat(accordion): add controllerAs support
Browse files Browse the repository at this point in the history
- Expose the controller to the view via `controllerAs`

Closes #4138
  • Loading branch information
wesleycho committed Aug 7, 2015
1 parent a0e1c91 commit 9865ee8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
// and adds an accordion CSS class to itself element.
.directive('accordion', function () {
return {
restrict:'EA',
controller:'AccordionController',
restrict: 'EA',
controller: 'AccordionController',
controllerAs: 'accordion',
transclude: true,
replace: false,
templateUrl: function(element, attrs) {
Expand Down
24 changes: 20 additions & 4 deletions src/accordion/test/accordion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,36 @@ describe('accordion', function () {
});

describe('accordion', function () {
var scope, $compile, element;
var scope, $compile, $templateCache, element;

beforeEach(inject(function($rootScope, _$compile_) {
beforeEach(inject(function($rootScope, _$compile_, _$templateCache_) {
scope = $rootScope;
$compile = _$compile_;
$templateCache = _$templateCache_;
}));

it('should allow custom templates', inject(function ($templateCache) {
it('should expose the controller on the view', function () {
$templateCache.put('template/accordion/accordion.html', '<div>{{accordion.text}}</div>');

element = $compile('<accordion></accordion')(scope);
scope.$digest();

var ctrl = element.controller('accordion');
expect(ctrl).toBeDefined();

ctrl.text = 'foo';
scope.$digest();

expect(element.html()).toBe('<div class="ng-binding">foo</div>');
});

it('should allow custom templates', function () {
$templateCache.put('foo/bar.html', '<div>baz</div>');

element = $compile('<accordion template-url="foo/bar.html"></accordion>')(scope);
scope.$digest();
expect(element.html()).toBe('<div>baz</div>');
}));
});
});

describe('accordion-group', function () {
Expand Down

0 comments on commit 9865ee8

Please sign in to comment.