Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 来自不同组件的角度事件_Php_Angular_Typescript_Session_Service - Fatal编程技术网

Php 来自不同组件的角度事件

Php 来自不同组件的角度事件,php,angular,typescript,session,service,Php,Angular,Typescript,Session,Service,我试图在注销时销毁会话变量。在我的api.service.ts脚本中调用php脚本。发生此情况的页面正在从app.component.html运行 <button type="button" *ngIf="logoutbtn" class="btn btn-block" (click)="logout()">logout</button> api.service.ts文件包含调用php脚本的

我试图在注销时销毁会话变量。在我的api.service.ts脚本中调用php脚本。发生此情况的页面正在从app.component.html运行

<button type="button" *ngIf="logoutbtn" class="btn btn-block" (click)="logout()">logout</button>
api.service.ts文件包含调用php脚本的代码:

logoutUser(){
  return this.httpClient.get<Policy[]>(`${this.PHP_API_SERVER}/api/logout.php`, { withCredentials: true });
}
logoutUser(){
返回this.httpClient.get(`this.PHP\u API\u SERVER}/API/logout.PHP`,{withCredentials:true});
}

我如何从app.component.ts进行通信,并在代码行“close session here”上调用api.service.ts文件中的函数?

使用依赖项注入

  • 导入
    app.component.ts中的
    api.service.ts
    文件

  • 在构造函数中声明它

  • 像use使用
    deleteToken()
    方法一样使用它

  • EX-在注销函数中

    this.apiService.logoutUser().subscribe( response = > {
    
       console.log("user logged out with api call");
    
    })
    

  • 我添加了
    构造函数(privatedataservice:ApiService)
    然后运行
    this.dataService.logoutUser()但是我没有看到php脚本在另一端被调用。我在服务器中运行了一个错误日志,以查看是否正在调用它。这是正确的方法吗?@ConnorThomas你做对了吗?这是正确的方法。
    
    this.apiService.logoutUser().subscribe( response = > {
    
       console.log("user logged out with api call");
    
    })