Angularjs 从另一个控制器更新控制器

Angularjs 从另一个控制器更新控制器,angularjs,angular-services,Angularjs,Angular Services,我的页面上有两个处于活动状态的控制器: // For handling any changes made to the Recipe Window ctrl.controller('recipeCtrl', ['$scope', 'view_service', 'recipe_service', function($scope, view_service, recipe_service) { $scope.title = recipe_service.get_ti

我的页面上有两个处于活动状态的控制器:

// For handling any changes made to the Recipe Window
      ctrl.controller('recipeCtrl', ['$scope', 'view_service', 'recipe_service', function($scope, view_service, recipe_service) {
          $scope.title = recipe_service.get_title();
      }]);

      ctrl.controller('setNameCtrl', ['$scope', 'view_service', 'recipe_service', function($scope, view_service, recipe_service) {
          $scope.titleSet = recipe_service.get_title();
          $scope.setName = function(){
              recipe_service.set_title($scope.titleSet);
              //view_service.set_view_url({url:"partials/typeWindow.tpl.html"});
          };
      }]);
两个控制器都从该服务中提取:

serv.service('recipe_service', function(){
    var recipe = {
                        title:"ace",
                        type:"",
                        market:[],
                        attribute:[]
                        };

    return {
        get_title: function() {
            return recipe.title;
        },
        set_title: function(newTitle){
            recipe.title = newTitle;
        }      
    };
});
第二个控制器更新第一个控制器正在引用的“标题”。我的问题是,一旦第二个控制器更改了服务中的“标题”,第一个控制器就不会更新以反映这些更改。我认为需要做的是更新第一个控制器以引入这些新更改。有什么建议吗

// For handling any changes made to the Recipe Window
  ctrl.controller('recipeCtrl', ['$scope', 'view_service', 'recipe_service', function($scope, view_service, recipe_service) {
      $scope.curRecipe = recipe_service.recipe;
  }]);

  ctrl.controller('setNameCtrl', ['$scope', 'view_service', 'recipe_service', function($scope, view_service, recipe_service) {
      $scope.curRecipe = recipe_service.recipe;
      $scope.setName = function(){
          //view_service.set_view_url({url:"partials/typeWindow.tpl.html"});
      };
  }]);

serv.service('recipe_service', function(){

    return {
        recipe : {
                   title:"ace",
                   type:"",
                   market:[],
                   attribute:[]
                 },
        set_title: function(newTitle){
            recipe.title = newTitle;
        }      
    };
});
始终使用相同的对象将起作用。。。此对象可以在服务中定义,也可以使用

 angular.module("myApp",[]).value("myObject","Shared Value");
然后像这样把这个注入到你的控制器中

angular.module("myApp").controller("MyCtrl",function($scope,myObject){console.log(myObject)})
我还发布了一个plnkr,展示了一些选项:


请找到下面的标签