can i inherit a parent controller's variables?

后端 未结 5 683
北恋
北恋 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 15:45

    It might help you!!!

    Scope is a special JavaScript object that connects controller with views. Scope contains model data. In controllers, model data is accessed via $scope object.

    
    

    Scope Inheritance Scope is controller-specific. If we define nested controllers, then the child controller inherits the scope of its parent controller.

    
    

    Live example as give below.

    
        
           Angular JS Forms
        
        
           

    AngularJS Sample Application

    {{message}}
    {{type}}

    {{message}}
    {{type}}

    {{message}}
    {{type}}

提交回复
热议问题