ページでアクティブなコントローラーが 2 つあります。
// 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;
}
};
});
2 番目のコントローラーは、最初のコントローラーが参照している「タイトル」を更新します。私の問題は、2 番目のコントローラーがサービスで「タイトル」を変更すると、最初のコントローラーが更新されず、変更が反映されないことです。私が考える必要があるのは、最初のコントローラーを更新して新しい変更を取り込む方法です。その方法について何か提案はありますか?