0
我在使用Angular控制器的ASP.NET MVC Core應用程序中有一個客戶頁面。控制器正在調用API來獲取數據。第一次加載頁面時,這可以正常工作。 從此頁面,用戶可以導航到另一頁面以添加客戶。當新客戶被添加時,用戶被導航回主頁面。但是,新客戶沒有顯示在主頁面上,它看起來像API不再被調用,所以用戶被呈現舊數據。我在API解決方案中設置了一個斷點,以確認添加新客戶後API未被調用。客戶頁上從詳細信息頁面的角度重定向未顯示最新數據
加載數據:
function customerController($http) {
var vm = this;
vm.customers = [];
$http.get("http://myapi")
.then(function (response) {
angular.copy(response.data, vm.customers);
}, function (error) {
vm.errorMessage = "Failed to load data: " + error;
});
}
從細節頁面的主網頁重定向(也從一個角控制器):
vm.addCustomer = function() {
$http.post("http://myapi", vm.currentCustomer)
.then(function (response) {
$window.location.href = "./Customers";
}, function (error) {
vm.errorMessage = "Failed to save new customer";
});
}
的數據實際上存儲在數據庫中通過API,但在重定向的新數據沒有顯示。當我刷新主頁面時,新客戶仍未顯示。我應該強迫Angular以某種方式再次調用API嗎?主頁面控制器的構造函數在重定向後調用。
心靈的標籤,您正在使用AngularJS工作,沒有棱角。角是指2-> – Alex