Syl*_*ver 9 javascript angularjs
在我的角度项目中,当显示更改具有$location.path('/foobar')目标视图的路径但未重新加载数据时(通常在保存项目并返回列表后,列表不会更新).
我试图添加$route.reload()或$scope.apply(),但没有任何改变.
我不知道做这项工作有什么不对或缺失.
UPDATE
$location.url() 也没有'工作更新2 - 答案
好的,经过大量的评论和回答,我认为是时候结束这个了.
我认为这不是一个如此复杂的问题.
所以,我的结论,给你所说的是:
你们所有人都给了我一些好的建议,谢谢.
使用$window.location.href.重新加载页面.我只是查看$ location文件:
页面重新加载导航
$ location服务允许您仅更改URL; 它不允许您重新加载页面.当您需要更改URL并重新加载页面或导航到其他页面时,请使用较低级别的API $ window.location.href.
例:
$window.location.href = "/your/path/here";
Run Code Online (Sandbox Code Playgroud)
伪代码:-
app.controller('myController', ['$scope', '$location','$http', 'ItemListService'
function($scope, $location, $http, ItemListService){
$scope.data = function(){
ItemListService.getAllItems(); //get all the items;
};
$scope.saveMethod = function(item){
$scope.data = ItemListService.save(item); //this is the refresh part, return data through save method. Pull the latest data and bind it to the scope.
$location.path('/fooView'); //dont think you even need this if you are entering data in a modal sorta thing, which on the same view.
}
}]);
Run Code Online (Sandbox Code Playgroud)
你的服务应该是这样的,
app.service('ItemListService', function(){
this.getAllItems = function(){
//get the items from itemList
//return all the items
}
this.save = function(item){
//save the item in itemList
//**return all items again, call getAllItems here too.
}
});
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!!