can i inherit a parent controller's variables?

后端 未结 5 693
北恋
北恋 2021-02-01 15:34

Here is my code:

function ParentCtrl($scope) {
$scope.people = [\"Tom\", \"Dick\", \"Harry\"];
$scope.count = $scope.people.length;
}

function ChildCtrl($scope)         


        
5条回答
  •  滥情空心
    2021-02-01 16:06

    The $scope inheritance is based upon where you reference your controllers using ng-controller.

    If you have something like

    Then yes, the child controller will inherit the properties of the parent controller.

    Note : The child controller need not be defined on the direct child in the html. It can be any child within.

提交回复
热议问题