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

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

问题描述:

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

I have two controllers that are active on my page:

// 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"});
          };
      }]);

两个控制器都从这个服务中拉取:

Both controllers are pulling from this service:

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;
        }      
    };
});

第二个控制器更新第一个控制器引用的标题".我的问题是,一旦第二个控制器更改了服务中的标题",第一个控制器就不会更新以反映更改.我认为需要发生的是如何刷新第一个控制器以引入这些新更改.关于如何这样做的任何建议?

The second controller updates the "title" that the first controller is referencing. My problem is that once the second controller changes "title" in the service, the first controller is not updated to reflect the changes. What I am thinking that needs to happen is to some how refresh the first controller to pull in those new changes. Any suggestion on how to do so?

请找到下面的plunker

Please find the below plunker

http://plnkr.co/edit/UQgAC8bzcJkmsfCMyP84?p=preview