AngularJS: Wie kann ich Variablen zwischen Controllern übergeben?

Ich habe zwei Winkelregler:

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
}

Ich kann nicht verwendenCtrl1 InnerhalbCtrl2 weil es undefiniert ist. Aber wenn ich versuche, es so weiterzugeben ...

function Ctrl2($scope, Ctrl1) {
    $scope.prop2 = "Second";
    $scope.both = Ctrl1.prop1 + $scope.prop2; //This is what I would like to do ideally
}

Ich bekomme eine Fehlermeldung. Weiß jemand, wie man das macht?

Tun

Ctrl2.prototype = new Ctrl1();

Scheitert auch.

HINWEIS: Diese Controller sind nicht ineinander verschachtelt.

Antworten auf die Frage(15)

Ihre Antwort auf die Frage