window.location.href 在 Typescript 中不起作用

window.location.href doesn't work in typescript

本文关键字:不起作用 Typescript location href window      更新时间:2023-09-26

我正在尝试在我的应用程序中添加注销。 所以我调用 get/logout 网络服务,我有一个 url 作为响应。然后我使用此 url 将我的页面重定向到返回的 url。

这是我的代码:

 constructor(
$q: ng.IQService,
$location: ng.ILocationService,
$window: ng.IWindowService,
$http: ng.IHttpService
) {
this._$q = $q;
this._$location = $location;
this._$window = $window;
this.logout = () => {
  return $http
    .get(logoutUri, {})
    .success((resp:any): void  => {
      window.location.href = resp;
    });
};
}

另外,我得到了正确的网址,但我的页面没有重定向到特定的网址。

而不是;

window.location.href = resp

尝试

$location.path(resp);
$location.replace();