从另一个控制器angularjs传递变量范围

Pass variables scope from another controller angualrjs

我想将控制器中的作用域变量传递给另一个控制器。我试过了,还是不行 working.this 是我的代码:

.factory('MyService',function(){
   return {varId_agen:''};
})
.controller('InputEditCtrl',function($scope,MyService){
   $scope.MyService=MyService;
   $scope.id_agen = $scope.MyService;
})
.controller('dataBusCtrl',function($scope,Buses,$timeout,TxData,$ionicModal,MyService){
   $scope.editData = function(dataBus){
      Service.varId_agen= dataBus.id_agen;
      $scope.editModal.show();
   };
})

U 可以在服务中使用 setter 和 getter 方法来实现,检查此代码 `

angular.module('myApp', []).factory('myService', function () {
var o = {x:1, y:2};
return {
    getO: getO,
    setO: setO
};

function getO() {
    return o;
}
function setO(x, y) {
    o.x = x;
    o.y = y;
}

});

angular.module('myApp').controller('MyCtrlA', function ($scope, myService) {
myService.setO(3, 4);
});

angular.module('myApp').controller('MyCtrlB', function ($scope, myService) {
var o = myService.getO(); // {x:3, y:4}
  });    `