0
我在页面中有两个表,并且在单击第一个表上的一行时,我想调用一个ajax请求来更新第二个表。AngularJS - 将ajax请求传递给另一个控制器
我想用两个控制器做到这一点,他们每个人都用ng-repeat填充行的值。 我烧掉了每个我能负担得起的神经元,而且我仍然难倒。
这是我的代码
app.controller("TermsCtrl", function($scope, $http) {
$http.get('json.php').then(function(res) {
$scope.wordfreq = res.data;
$scope.decodeURIComponent = decodeURIComponent;
$scope.unescape = unescape;
});
$scope.go = function(id) { // This makes the rows clickable and calls the next results
return $http.get('json2.php?word=' + id).then(function(result) {
secondtable = result.data;
console.log(secondtable); // I see the objects!
return secondtable;
});
};
});
app.controller("TermsCtrl2", function($scope, secondtable) {
$scope.secondfeq = secondtable;
console.log(scope.secondfeq); // No dice
});
任何想法如何从点击的secondtable
结果到TermsCtrl2
控制器?
欢呼
什么是'这里secondtable'?它不是一个服务的名称,它不是'$ scope'上的属性,你是否试图在窗口中声明它为全局变量? – Claies
'secondtable'应该是我想要接管第二个控制器的数据 – bronze
是的,但是变量声明在哪里? – Claies