Concerning widgets, how can I prevent $watch from firing with each character input?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2020 12:39 PM
Okay, kind of a widget/ portal noob here. What I am trying to accomplish: I have a string field on a widget and I would like to pass the value inserted by a user there into a script include. Currently I am using $watch on the var but it is calling that method every time the field changes which is obviously not desirable. How can I change it so that it only fires when the user is done inserting their string? i.e. onChange
current code
$scope.$watch('c.sco_id', function(sco_id) {
if (sco_id) {
alert(sco_id);
}
})

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2020 12:55 PM
Hi,
For this use case, you should use ng-change instead of watching the variable changes. Example
<input type="text" ng-change="myFunc()" ng-model="myValue" />
Controller
$scope.myFunc = function() {
console.log("I am changed");
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2020 01:26 PM
probably, but ng-change still gets called for each character i input
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2022 12:18 PM
Create a separate field that is hidden and updates when the field you update is updated. so have the controller watch the hidden field which updates on client script (which only triggers when focus is left the field) and then it will only update when the update is complete.