单击按钮打开 url 但来自 ts 函数
click button to open url but from ts function
要求:
我们需要在新 window 上打开一个 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 ?
}
您需要使用 javascript 的 window.open
方法在单击按钮时打开 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');
}
要求:
我们需要在新 window 上打开一个 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 ?
}
您需要使用 javascript 的 window.open
方法在单击按钮时打开 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');
}