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

feat(accordion): add controllerAs support #4138

Closed
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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