Angular 来自不同组件的事件
Angular Events from different components
我试图让我的会话变量在注销时被销毁。在我的 api.service.ts 脚本中调用 php 脚本。发生这种情况的页面来自 app.component.html。
运行
<button type="button" *ngIf="logoutbtn" class="btn btn-block" (click)="logout()">logout</button>
正在从我的 app.component.ts 脚本中调用 logout() 函数。
logout()
{
this.dataService.deleteToken();
// Close session here
window.location.href = window.location.href;
}
api.service.ts 文件有我调用 php 脚本的代码:
logoutUser(){
return this.httpClient.get<Policy[]>(`${this.PHP_API_SERVER}/api/logout.php`, { withCredentials: true });
}
我如何从我的 app.component.ts 进行通信并调用那行代码“在此处关闭会话”来调用我的 api.service.ts 文件中的函数?
使用依赖注入,
导入 api.service.ts
文件到 app.component.ts
在构造函数中声明它
像使用deleteToken()
方法一样使用它
EX - 在注销函数中
this.apiService.logoutUser().subscribe( response = > {
console.log("user logged out with api call");
})
我试图让我的会话变量在注销时被销毁。在我的 api.service.ts 脚本中调用 php 脚本。发生这种情况的页面来自 app.component.html。
运行<button type="button" *ngIf="logoutbtn" class="btn btn-block" (click)="logout()">logout</button>
正在从我的 app.component.ts 脚本中调用 logout() 函数。
logout()
{
this.dataService.deleteToken();
// Close session here
window.location.href = window.location.href;
}
api.service.ts 文件有我调用 php 脚本的代码:
logoutUser(){
return this.httpClient.get<Policy[]>(`${this.PHP_API_SERVER}/api/logout.php`, { withCredentials: true });
}
我如何从我的 app.component.ts 进行通信并调用那行代码“在此处关闭会话”来调用我的 api.service.ts 文件中的函数?
使用依赖注入,
导入
api.service.ts
文件到app.component.ts
在构造函数中声明它
像使用
deleteToken()
方法一样使用它EX - 在注销函数中
this.apiService.logoutUser().subscribe( response = > { console.log("user logged out with api call"); })