我是新手angularJS
。我已经开始学习CRUD操作。我遇到一个问题,当我delete
条目然后页面应该reload
使用angularJs重新加载页面
我也经历了$location
和$route
太。并实施如下:
config
app.config(function ($locationProvider, $routeProvider) {
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix = '!';
$routeProvider.when('/', {
templateUrl: '/views/index.html',
controller: 'MainCtrl'
});
$routeProvider.when('/this',{
templateUrl: '/views/about.html',
controller: 'MainCtrl'
});
});
当action成功那么我的写作:
$location.path('/this');
但是当我做到这一点,则url
变化从http://localhost/someapp
到http://this
但页面不刷新。在这种情况下我应该怎么做,请帮助我们吗?
Edit
:
这是我deletion code
:
$scope.deletecode = function (id) {
name = '';
if (confirm("are you sure to Delete the name")) {
$http({
method: 'POST',
url: 'rohit.php',
data: {
"name": name,
"id": id,
"delete": "true"
},
}).
success(function (data, status, headers, config) {
alert("data deleted successfully");
$location.path('/this');
}).
error(function (data, status, headers, config) {
alert("Unable to load data.");
});
} else {
alert("Data deletion cancelled by user ... ");
}
};
在初始化我从一个PHP文件中获取的数据:
$http({
method: 'GET',
url: 'test.php'
}).
success(function (data, status, headers, config) {
$scope.samples = data;
}).
error(function (data, status, headers, config) {
alert("Unable to load data.");
});
所有的数据都存储在$scope.samples
返回两件事user_id
和name
我不确定您是否确实想要刷新页面。删除项目(如果操作正确)将更新视图,而无需刷新页面。 – xbonez
该视图未更新,如何更新视图,我发布了我的删除函数 –
更新了我的代码 –