AngularJS: ¿Cómo puedo pasar variables entre los controladores?
Tengo dos controladores angulares:
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
}
No puedo usarCtrl1
dentroCtrl2
Porque no está definido. Sin embargo si trato de pasarlo así ...
function Ctrl2($scope, Ctrl1) {
$scope.prop2 = "Second";
$scope.both = Ctrl1.prop1 + $scope.prop2; //This is what I would like to do ideally
}
Me sale un error. ¿Alguien sabe como hacer esto?
Obra
Ctrl2.prototype = new Ctrl1();
También falla.
NOTA: Estos controladores no están anidados uno dentro del otro.