Angularjs 为什么不重新招标?
当我在html中调用$scope.remove时,它会调用rerender函数,然后自动更新html中的数据 当我调用$scope.post时,它调用rerender函数并记录新数据。但是,它不会自动重新加载html。我必须刷新页面才能看到最新的数据 我已经考虑过使用$apply,但我不明白它是如何更新为remove而不是post的 控制器:Angularjs 为什么不重新招标?,angularjs,angularjs-scope,Angularjs,Angularjs Scope,当我在html中调用$scope.remove时,它会调用rerender函数,然后自动更新html中的数据 当我调用$scope.post时,它调用rerender函数并记录新数据。但是,它不会自动重新加载html。我必须刷新页面才能看到最新的数据 我已经考虑过使用$apply,但我不明白它是如何更新为remove而不是post的 控制器: var updateData = function (resp){ $scope.data = resp.data; console.log($s
var updateData = function (resp){
$scope.data = resp.data;
console.log($scope.data);
}
$scope.getEntries = function (){
return $http({
method: 'GET',
url: '/allEntries'
}).then(updateData)
};
$scope.post = function (){
return $http({
method: 'POST',
url: '/newEntry',
data: $scope.entry
}).then(function (resp){
$scope.getEntries();
})
};
$scope.remove = function (opp){
return $http({
method: 'POST',
url: '/deleteEntry',
data: opp
}).then(function (){
$scope.getEntries();
})
}
我认为这可能与在不同的html文件中调用函数有关,但由于它们都有相同的控制器,我认为情况并非如此
<html>
<body ng-app = "app">
<div ng-controller = "controller">
<form ng-submit = "post()">
<input type="submit" value="Submit">
</form>
</div>
</body>
</html>`
<html>
<body ng-app = "app">
<div ng-controller = "controller">
<ul>
<li ng-repeat = "job in data" ><input type = "button" ng-click = "remove(opp)" value="Delete"></li>
</ul>
</div>
</body>
</html>`
`
`
事实上,您有两个不同的部分,每个部分都有自己的控制器,因此每个部分都有自己的范围:
- 显示项目列表的一种
- 一个什么也看不出来的人