angularJS: How to call child scope function in parent scope

前端 未结 4 2004
难免孤独
难免孤独 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:17

    Let me suggest another solution:

    var app = angular.module("myNoteApp", []);
    
    
    app.controller("ParentCntl", function($scope) {
        $scope.obj = {};
    });
    
    app.controller("ChildCntl", function($scope) {
        $scope.obj.get = function() {
                return "LOL";    
        };
    });
    

    Less code and using prototypical inheritance.

    Plunk

提交回复
热议问题