click button to open url but from ts function
11,736
Solution 1
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);
}
Solution 2
HTML:
<button ion-button (click)="saveit()">Save</button>
Component:
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');
}
Author by
user2828442
Updated on June 27, 2022Comments
-
user2828442 almost 2 years
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 ? }