My current challenge involves monitoring user input in a text field and validating the input when a comma is typed, instead of using ng-click="action()"
. I am looking to implement something like Comma-Typed="action()", but my attempts with ng-change and scope.watch() have been unsuccessful.
This is what I have tried so far:
<input id="tagInsert" type="text" name="newTag" ng-model="newTag" ng-model-options="{debounce: 100}" typeahead="tag for tag in getTags($viewValue)" class="form-control" typeahead-loading="loadingTags" ng-keydown="addInterestOnEvent($event)" ng-disabled="interestLimit" autocomplete="off" ng-change="alert('stuff')" />
Controller :
$scope.$watch('newTag', function(val) {
if (val.keyCode == 188) { // KeyCode For comma is 188
alert('comma added');
action();
}
});
I also attempted using ng-keydown:
$scope.addInterestOnEvent = function (event) {
if (event.which !== 188) return;
event.preventDefault();
$scope.addInterest();
};
Unfortunately, this method did not produce the desired results.
EDIT
I found out that it works with ng-keydown="action()"
, I had simply forgotten to restart the server.