我有一个重置链接,旨在重置我的angular js应用程序。。。
<a ng-click="resetApp()">reset</a>
我正在处理主控制器中的按钮按下。。。
$scope.resetApp = function(){
if(confirm("You will lose data...")){
$scope.user.reset();
// not sure how to do this in more angular js way
window.location = "/#";
}
}
我不确定像我所做的那样设置window.location
是否是正确的做事方式。它对我有效,但似乎不是正确的方式,而且我还没能在网上找到如何做到这一点。
我一直在使用所谓的AngularJS方式,至少路由是由AngularJS处理的,而不是直接由浏览器处理的。
function Ctrl($scope, $location) {
$scope.resetApp = function(){
...
$location.url('/');
}
}
路径是Route Provider
中定义的路径,如下所示:
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'index.html',
controller: 'Ctrl'
}).
...