refactor(controllers): only assign to parent scope when needed

This commit is contained in:
Andy Joslin
2014-03-21 09:59:42 -05:00
parent 38acea337a
commit f594f653d5
3 changed files with 6 additions and 9 deletions

View File

@@ -124,14 +124,14 @@ function barDirective(isHeader) {
alignTitle: $attr.alignTitle || 'center'
});
$parse($attr.controllerBind ||
(isHeader ? '$ionicHeaderBarController' : '$ionicFooterBarController')
).assign($scope, hb);
var el = $element[0];
//just incase header is on rootscope
var parentScope = $scope.$parent || $scope;
$parse($attr.controllerBind ||
(isHeader ? '$ionicHeaderBarController' : '$ionicFooterBarController')
).assign(parentScope, hb);
if (isHeader) {
$scope.$watch(function() { return el.className; }, function(value) {
var isSubheader = value.indexOf('bar-subheader') !== -1;

View File

@@ -120,7 +120,7 @@ angular.module('ionic.ui.sideMenu', ['ionic.service.gesture', 'ionic.service.vie
$scope.sideMenuContentTranslateX = 0;
$parse($attrs.controllerBind || '$ionicSideMenusController')
.assign($scope.$parent || $scope, this);
.assign($scope, this);
}],
replace: true,
transclude: true,

View File

@@ -18,11 +18,8 @@ describe('Ionic Angular Side Menu', function() {
var el = $compile('<ion-side-menus controller-bind="supermodel"></ion-side-menus>')($rootScope.$new());
var scope = el.scope();
expect(el.controller('ionSideMenus')).toBeDefined();
expect(scope.$parent.supermodel).toBe(el.controller('ionSideMenus'));
expect(scope.supermodel).toBe(el.controller('ionSideMenus'));
}));
it('should init with custom model attr', function() {
});
});
describe('Ionic Side Menu Content Directive', function () {