refactor(controllers): assign to parent scope if possible

This commit is contained in:
Andy Joslin
2014-03-21 09:50:09 -05:00
parent aa280910df
commit 38acea337a
4 changed files with 10 additions and 8 deletions

View File

@@ -43,7 +43,7 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca
.data('$$ionicScrollController', this);
$parse(scrollViewOptions.controllerBind || '$ionicScrollController')
.assign($scope.$parent, this);
.assign($scope.$parent || $scope, this);
if (!angular.isDefined(scrollViewOptions.bouncing)) {
ionic.Platform.ready(function() {

View File

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

View File

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

View File

@@ -15,10 +15,10 @@ describe('Ionic Angular Side Menu', function() {
}));
it('should assign sideMenuController with option', inject(function($compile, $rootScope) {
var el = $compile('<ion-side-menus controller-bind="supermodel"></ion-side-menus>')($rootScope);
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.supermodel).toBe(el.controller('ionSideMenus'));
expect(scope.$parent.supermodel).toBe(el.controller('ionSideMenus'));
}));
it('should init with custom model attr', function() {