Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

click button to open url but from ts function

Requirement:

We need to open a php page on a new window. We have achieved like this way as shown below

.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;
}

But we want to achieve it differently. Need to click a button from html, which will call a function, from this function everything should happen.

.html

 <button ion-button  (click)="saveit">Save</button>

.ts

saveit(){
// the url,html tag should be called from here , how ?
}
like image 722
user2828442 Avatar asked Oct 19 '25 10:10

user2828442


1 Answers

You need to use window.open method of javascript to open URL on button click, like this -

 <button ion-button  (click)="saveit()">Save</button>
saveit(){
// the url,html tag should be called from here , how ?
window.open(URL);
}
like image 165
Pardeep Jain Avatar answered Oct 21 '25 01:10

Pardeep Jain