要求:
我们需要在新窗口中打开一个 php 页面。我们实现了这样的成就,如下所示
.html code
<a target="_blank" href="{{pdf}}">Download Pdf</a>
.ts code
ngOnInit()
{
this.loggedinuser = localStorage.getItem("USERNAME");
console.log(this.loggedinuser);
this.pdf = 'http://219.90.67.154/report-service/quicktask/TCPDF/examples/test-tcpdf.php?loggedinuser='+this.loggedinuser;
}
但我们希望以不同的方式实现它。需要从html中单击一个按钮,它将调用一个函数,从这个函数中一切都应该发生。
.html
<button ion-button (click)="saveit">Save</button>
.ts
saveit(){
// the url,html tag should be called from here , how ?
}
你需要使用window.open
javascript的方法在点击按钮时打开URL,像这样 -
<button ion-button (click)="saveit()">Save</button>
saveit(){
// the url,html tag should be called from here , how ?
window.open(URL);
}
HTML:
<button ion-button (click)="saveit()">Save</button>
元件:
saveit() {
let loggedinuser = localStorage.getItem("USERNAME");
let url = 'http://219.90.67.154/report-service/quicktask/TCPDF/examples/test-tcpdf.php?loggedinuser=' + this.loggedinuser;
window.open(url, '_blank');
}