can i inherit a parent controller's variables?

后端 未结 5 685
北恋
北恋 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:05

    By default, child scopes prototypically inherit from the parent scope (see Scope), so you already have access to the parent controller's $scope properties in the child. To prove it:

    function ChildCtrl($scope) {
        alert($scope.people)
    }
    

提交回复
热议问题