在Angular应用程序中打开POST URL并使用重定向,可以使用HttpClient模块来发送POST请求,并使用Router模块进行重定向。
示例代码如下:
import { HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';
@Injectable()
export class YourService {
constructor(private http: HttpClient, private router: Router) {}
postData(url: string, data: any) {
return this.http.post(url, data).subscribe(res => {
// Redirect to new page if required
this.router.navigateByUrl('/newpage');
});
}
}
在上面的代码中,HttpClient
模块被注入到服务中,post
方法被使用来发送POST请求。当请求完成时,subscribe
方法被使用来处理响应,并在需要时使用Router
模块进行重定向。