AngularJS access parent scope from child controller

前端 未结 9 1736
南方客
南方客 2020-11-22 07:30

I\'ve set up my controllers using data-ng-controller=\"xyzController as vm\"

I have a scenario with parent / child nested controllers. I have no problem

9条回答
  •  长发绾君心
    2020-11-22 08:06

    When you are using as syntax, like ParentController as parentCtrl, to define a controller then to access parent scope variable in child controller use following :

    var id = $scope.parentCtrl.id;
    

    Where parentCtrl is name of parent controller using as syntax and id is a variable defined in same controller.

提交回复
热议问题