0
app.factory('dataPassingService', function() {
var savedData = {};
function set(data) {
savedData = data;
}
function get() {
return savedData;
}
return {
set: set,
get: get
}
});
$scope.text = '9';
dataPassingService.set($scope.text);
控制器2
$scope.mes = dataPassingService.get();
alert("the scope is "+scope.mes);
我通過$ scope.text從控制器1使用app.factory 2和它的工作完美控制器。我想將更多的範圍從controller1傳遞給controller2例如我想通過$ scope.text ='9'和scope.text1 = '10',然後通過datapassingService.get()將其傳遞給controller2。預先.Thanks