我正在尝试将值从一个控制器传递给其他控制器。两个控制器都在同一模块上。我尝试创建服务。问题是我能够从第一个控制器传递值到服务,但无法在第二个控制器上检索该值。任何帮助,将不胜感激。在项目页面上给出。
控制器1 (在商品页面上):
addLast(...)
控制器2(位于文章页面上):
itpApp.controller("itpAppControllerKB", function($scope, sharedProperties, $location) {
$scope.showArticles = function(myValue) {
console.log('myValue: ' + myValue);
sharedProperties.setListName(myValue);
window.location.href = "/portal/articles";
};
});
服务:
itpApp.controller("itpAppControllerKBArticle", function($scope, sharedProperties) {
$scope.article = sharedProperties.getListName();
console.log('selTopic: ' + $scope.article);
}
答案 0 :(得分:1)
不要在您的服务上使用return语句。这是一个例子:
itpApp.service('sharedProperties', function () {
this.list_name = '';
this.getListName = function() {
return this.list_name;
};
this.setListName = function(name) {
this.list_name = name;
};
});