ionic 2 not updating the Counter property in html

有些话、适合烂在心里 提交于 2020-02-04 01:29:05

问题


I have this simple example which does update the Counter value in my HomePage class.

But in the html view:

 <p>{{Counter}}</p>

this remains zero.

The method:

  ondrag(event, item) {
    let percent = event.getSlidingPercent();
    if (percent === 1) {            
        event.close();
        this.Counter--;
    }
    if (percent + 1 === 0) {
        event.close();
        this.Counter++;
    }
}

works on my machine if i add logs for each if

Here is the code on plnkr: https://plnkr.co/edit/7Q4wDtZjIS1zBDsF0etS

Any suggestions?


回答1:


This topic was already discussed in another SO thread: https://stackoverflow.com/a/35106069/2256927

This might resolve your problem!




回答2:


Your ondrag handler is attempting to use item which is actually a string - literally the iterated value of the items array. This means your code is throwing an exception on item.getSlidingPercent which doesn't exist. Try using event instead of item, like this:

  ondrag(event, item) {
    let percent = event.getSlidingPercent();
    if (percent === 1) {   
        event.close();
        this.Counter--;
    }
    if (percent + 1 === 0) {
        event.close();
        this.Counter++;
    }
  }


来源:https://stackoverflow.com/questions/39581470/ionic-2-not-updating-the-counter-property-in-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!