From 02872dc1feda38c068a2e0379e3d0d855f838aa0 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Fri, 7 Aug 2015 07:51:39 -0700 Subject: [PATCH] feat(buttons): add `controllerAs` support - Expose controller to the view for `btnCheckbox` and `btnRadio` directives Closes #4140 --- src/buttons/buttons.js | 2 ++ src/buttons/test/buttons.spec.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/buttons/buttons.js b/src/buttons/buttons.js index dc4dddcd8e..b601da60ca 100644 --- a/src/buttons/buttons.js +++ b/src/buttons/buttons.js @@ -14,6 +14,7 @@ angular.module('ui.bootstrap.buttons', []) return { require: ['btnRadio', 'ngModel'], controller: 'ButtonsController', + controllerAs: 'buttons', link: function (scope, element, attrs, ctrls) { var buttonsCtrl = ctrls[0], ngModelCtrl = ctrls[1]; @@ -45,6 +46,7 @@ angular.module('ui.bootstrap.buttons', []) return { require: ['btnCheckbox', 'ngModel'], controller: 'ButtonsController', + controllerAs: 'button', link: function (scope, element, attrs, ctrls) { var buttonsCtrl = ctrls[0], ngModelCtrl = ctrls[1]; diff --git a/src/buttons/test/buttons.spec.js b/src/buttons/test/buttons.spec.js index 70b5513563..327bb1ef3b 100644 --- a/src/buttons/test/buttons.spec.js +++ b/src/buttons/test/buttons.spec.js @@ -16,6 +16,17 @@ describe('buttons', function () { return el; }; + it('should expose the controller to the view', inject(function ($templateCache) { + var btn = compileButton('', $scope); + var ctrl = btn.controller('btnCheckbox'); + expect(ctrl).toBeDefined(); + + ctrl.text = 'foo'; + $scope.$digest(); + + expect(btn.html()).toBe('foo'); + })); + //model -> UI it('should work correctly with default model values', function () { $scope.model = false; @@ -135,6 +146,17 @@ describe('buttons', function () { return el.find('button'); }; + it('should expose the controller to the view', inject(function ($templateCache) { + var btn = compileButtons('', $scope); + var ctrl = btn.controller('btnRadio'); + expect(ctrl).toBeDefined(); + + ctrl.text = 'foo'; + $scope.$digest(); + + expect(btn.html()).toBe('foo'); + })); + //model -> UI it('should work correctly set active class based on model', function () { var btns = compileButtons('', $scope);