matata
February 17, 2017, 9:58am
1
Hi, I have this:
<button ion-item *ngFor="let item of items" (click)="goToDetails(item.id)">
I need send two parameters…
I use:
<button ion-item *ngFor="let item of items" (click)="goToDetails(item.id, item.title)">
But now working for me.
Any help please?
2 Likes
Delboii
February 17, 2017, 10:55am
2
In your typescript does ‘goToDetails()’ accept two parameters?
Your function should look something like :
gotoDetails(id:string, title:string){
}
4 Likes
and if you want to set the second parameter as optional:
gotoDetails(id:string, title?:string){
}
or if you want to set a default value, if the second parameter is not set
gotoDetails(id:string, title?:string = 'defaultValue){
}
4 Likes
Delboii
February 17, 2017, 11:43am
4
In your example above :
gotoDetails(id:string, title?:string){
}
Does this make the title parameter optional or the type optional? Does it save you having to write two constructors or does it mean we can use any type, i am thinking the former just want to double check
ramon
February 17, 2017, 1:04pm
5
Title parameter will be optional. You can call goToDetails function with one or two parameters.
Delboii
February 17, 2017, 1:09pm
6
Ahh okay, thank you for answering. Perhaps used wrong word constructor but sweet saves you having to write the two functions.
keep in mind that this types are not there after buildprocess, and the compiler do not know if you call this function from a template with invalid parameters. But for testing and better code you should type everything
1 Like
devsm
November 28, 2017, 1:59pm
8
I wrote a function for login with a if and in the html I pass name and password but the if is never verified, in the log the values are undefined…
HTML
<button ion-button id="login-btn" (click) = "verifyAccess(user, pwd)">Login</button>
(user and password are id’s of text input)
LOGIN.TS
verifyAccess(name:string, pwd:string){...}
1 Like
hi there,
how you can read this parameter in another page thank you