angularJS: How to call child scope function in parent scope

前端 未结 4 1998
难免孤独
难免孤独 2020-11-28 03:41

How can call a method defined in child scope from its parent scope?

function ParentCntl() {
    // I want to call the $scope.get here
}

function ChildCntl($         


        
4条回答
  •  醉梦人生
    2020-11-28 04:02

    You can make child object.

    var app = angular.module("myApp", []);
    
    
    app.controller("ParentCntl", function($scope) {
        $scope.child= {};
        $scope.get = function(){
          return $scope.child.get(); // you can call it. it will return 'LOL'
        }
       // or  you can call it directly like $scope.child.get() once it loaded.
    });
    
    app.controller("ChildCntl", function($scope) {
        $scope.obj.get = function() {
                return "LOL";    
        };
    });
    

    Here child is proving destination of get method.

提交回复
热议问题