Update parent scope variable in AngularJS

后端 未结 5 1586
不思量自难忘°
不思量自难忘° 2020-11-27 10:45

I have two controllers, one wrapped within another. Now I know the child scope inherits properties from the parent scope but is there a way to update the parent scope variab

5条回答
  •  星月不相逢
    2020-11-27 11:19

    This also works (but not sure whether this follows best practice or not)

    app.controller('ctrlParent',function($scope) {
        $scope.simpleValue = 'x';
    });
    
    app.controller('ctrlChild',function($scope){
        $scope.$parent.simpleValue = 'y';
    });
    

提交回复
热议问题