javascript - How to update parent scope in AngularJS? -
javascript - How to update parent scope in AngularJS? -
i tried update parent scope kid controller using 2 solutions can't create work. apply()
didn't work
html :
<div ng-controller="controllera"> <div ng-show="tab_selected == 1">content1</div> <div ng-show="tab_selected == 2">content2</div> <div ng-controller="controllerb"> <span ng-click="updatescope()"></span> </div> </div>
js :
app.controller('controllera', ['$scope', function ($scope) { $scope.tab_selected = 1; }]); app.controller('controllerb', ['$scope', function ($scope) { $scope.updatescope = function(){ $scope.tab_selected = 2; // $scope.apply(function(){ $scope.tab_selected = 2; }); } }]);
you can't update primitive attributes in parent object, object attributes. need use:
$scope.someobject= {}; $scope.someobject.tab_selected= 2;
javascript angularjs angularjs-scope
Comments
Post a Comment