问题
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