如何重载然后重定向到另一个视图

AngularJS How to reload then redirect to another view?

本文关键字:重定向 另一个 视图 然后 何重载 重载      更新时间:2023-09-26

我试图使一些按钮消失,当我注销,但如果我不放重新加载命令,它不会重新加载和按钮不会消失。在我放置reload命令后,视图不会改变,因为进程在reload行结束。

下面是我的代码:

$scope.logout = function(){
    deleteCookie("Username","/");
    location.reload();
    $location.path('/view1');

}

请帮忙!

UPATE: app.js

'use strict';
// Declare app level module which depends on views, and components
angular.module('myApp', [
  'ngRoute',
  'myApp.view1',
  'myApp.view2',
  'myApp.viewLogin',
  'myApp.SaveCafeDetail',
  'myApp.viewUserprofile',
  'myApp.viewManageuser',
  'myApp.viewEditcafe',
  'myApp.version'
]).
config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  $locationProvider.hashPrefix('!');
  $routeProvider.otherwise({redirectTo: '/view1'});
}]);

您可以使用绝对url或者只是在您的<a>标签上添加target="_self",如果您在HTML中使用它。

要重新加载到另一个视图,只需使用:

$state.go("your_view_name");

希望这对你有帮助!

我建议这样做…

     $scope.logout = function(){
     deleteCookie("Username","/");
        if (-----)  {   //deletecokkie value is null 
       window.location = "http://.../..."  //full URL of the designation;
          }
    }