Angular2在模板中调用函数时使用左侧操作符

时间:2016-11-11 08:52:03

标签: angular typescript

我的组件中有以下功能:

{id: 1,
 name: 'About',
 slug: 'about',
 children: [ 
             {
             id: 2,
             name: 'Team',
             slug: 'team',
             children: [
                         {
                         id: 3
                         name: 'Cameron'
                         slug: 'cameron'
                         ...

并在我的模板中:

public limit: number = 3

public logLimit(limit) {
  console.log(limit)
}

但是,当我点击我的div时,记录的限制是3,我的<div (click)="logLimit(--limit)">Decrease and log limit</div> 操作员怎么没有工作?

1 个答案:

答案 0 :(得分:2)

AFAIK不支持此功能。

您可以使用

<div (click)="limit = limit - 1;logLimit(limit)">Decrease and log limit</div>

Angular2模板绑定不支持完整的TS / JS语法。这不是问题,而是故意的。

相关问题