15
AngularJS:如何在控制器之间传递变量?
我有两个Angular控制器: function Ctrl1($scope) { $scope.prop1 = "First"; } function Ctrl2($scope) { $scope.prop2 = "Second"; $scope.both = Ctrl1.prop1 + $scope.prop2; //This is what I would like to do ideally } 我无法使用Ctrl1内部,Ctrl2因为它是未定义的。但是,如果我尝试像这样传递它… function Ctrl2($scope, Ctrl1) { $scope.prop2 = "Second"; $scope.both = Ctrl1.prop1 + $scope.prop2; //This is what I would like to do …