Nativescript Angular 2 - 如何在 tap 函数中传递变量 (xml)?
Nativescript Angular 2 - How do I pass variables in tap function (xml)?
我有一个用户 post 的列表视图。我想实现一个类似的功能。我想将 post id 传递给函数,这样我就可以将类似的东西添加到数据库中。
按下 Stacklayout 应该会触发点赞功能。
home.component.html(崩溃)
<ListView [items]="posts">
<ng-template let-post="item">
<StackLayout (tap)="likePost( {{ post.id }} )>
...
</StackLayout>
</ng-template>
</ListView>
<ListView [items]="posts">
<ng-template let-post="item">
<StackLayout (tap)="likePost(post.id)>
...
</StackLayout>
</ng-template>
</ListView>
在你的home.component.ts
likePost(id) {
//Use Id here and register the line
}
我有一个用户 post 的列表视图。我想实现一个类似的功能。我想将 post id 传递给函数,这样我就可以将类似的东西添加到数据库中。
按下 Stacklayout 应该会触发点赞功能。
home.component.html(崩溃)
<ListView [items]="posts">
<ng-template let-post="item">
<StackLayout (tap)="likePost( {{ post.id }} )>
...
</StackLayout>
</ng-template>
</ListView>
<ListView [items]="posts">
<ng-template let-post="item">
<StackLayout (tap)="likePost(post.id)>
...
</StackLayout>
</ng-template>
</ListView>
在你的home.component.ts
likePost(id) {
//Use Id here and register the line
}