我有一个重置链接,用于重置我的角度js app ...
<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
是正确的做事方式。它对我有用,但似乎不是正确的方法,而且我无法在网上找到它。
答案 0 :(得分:10)
我一直在使用所谓的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'
}).
...