【问题标题】:click button to open url but from ts function单击按钮打开 url 但来自 ts 函数
【发布时间】:2018-11-03 08:55:38
【问题描述】:

要求:

我们需要在新窗口中打开一个 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 ?
}

【问题讨论】:

标签: angular typescript ionic-framework ionic2 ionic3


【解决方案1】:

你需要使用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);
}

【讨论】:

  • 别忘了应该是 (click)="saveit()"
【解决方案2】:

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');
}

【讨论】:

    猜你喜欢
    • 2022-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-14
    • 2017-12-12
    • 2014-07-28
    • 2016-07-26
    • 2015-09-13
    相关资源
    最近更新 更多