bug: Template bindings are not updated in gesture callback function
See original GitHub issueBug Report
Ionic version:
[x] 5.x
Current behavior: Implementing a swipe gesture with the GestureController doesn’t invoke change detection. Values that get changed in onEnd are not updated in Angular-bound template elements.
Expected behavior: Angular-bound values which are changed in onEnd callback function of the SwipeGesture should be updated on the page.
Steps to reproduce:
Use the sample code below to reproduce the issue. It implements a swipe gesture which increases a counter variable. It shows the value on the console on each swipe. But the updated value is not reflected on the page itself where the output is bound via template binding.
Related code:
Template:
<ion-content #contentElement>
{{ counter }}
</ion-content>
Typescript:
export class TestPage {
counter = 0;
swipeGesture: Gesture;
@ViewChild('contentElement', { static: true, read: ElementRef }) contentElement: ElementRef;
constructor(private gestureController: GestureController) { }
ionViewDidEnter() {
this.swipeGesture = this.gestureController.create({
el: this.contentElement.nativeElement,
gestureName: 'swipe',
onEnd: () => this.onSwipeEnd(),
});
this.swipeGesture.enable();
}
private onSwipeEnd() {
this.counter++;
console.log(this.counter);
}
}
Ionic info:
Ionic:
Ionic CLI : 5.4.16 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 5.0.0
@angular-devkit/build-angular : 0.803.23
@angular-devkit/schematics : 8.3.23
@angular/cli : 8.3.23
@ionic/angular-toolkit : 2.1.2
Capacitor:
Capacitor CLI : 1.4.0
@capacitor/core : 1.4.0
Cordova:
Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : none
Cordova Plugins : no whitelisted plugins (0 plugins total)
Utility:
cordova-res : not installed
native-run : not installed
System:
Android SDK Tools : 26.1.1 (/Users/jens/Library/Android/sdk)
ios-deploy : 1.9.2
NodeJS : v12.14.0 (/usr/local/bin/node)
npm : 6.13.7
OS : macOS Catalina
Xcode : Xcode 11.3.1 Build version 11C504
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
bug: Template bindings are not updated in gesture callback ...
Implementing a swipe gesture with the GestureController doesn't invoke change detection. Values that get changed in onEnd are not updated in ...
Read more >Angular5 template binding, callback function called more than ...
Angular handles the binding between the model and the dom (component and template file). To do this the application ticks (change detection ...
Read more >Layouts and binding expressions | Android Developers
When a callback is used in an expression, data binding automatically creates the necessary listener and registers it for the event. When the ......
Read more >Notification.requestPermission cannot be called on load events
This behaviour is causing notification to fail on callbacks, even if the callback originates from logic with a click event. e.g. The user...
Read more >Element: <oj-diagram> - Oracle
When the template is executed, the component's binding context is extended with the following properties: $current - an object that contains ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@JensWinter A simple getaway fix is to add changeDetection in your component configuration. Example would be:
Constructor:
Function call:
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.