I'm building a Korean vocabulary trainer and I want to compare user input as people type.
In Korean and some other Asian languages, you compose letters with multiple keyup events. In Chrome, $scope.$watch, ng-keyup and ng-change only get triggered after the letter has been fully composed and either a new letter or a space has been entered. I don't mind AngularJS not triggering anything until the last letter has been fully composed but once the letter has been completed, it should trigger without having to add a whitespace or starting the next word.
HTML:
<form name="forms.vocabularyForm">
<input name="answer" id="answer" ng-model="vocabularyCtrl.answer" ng-change="vocabularyCtrl.checkChange()" ng-keyup="vocabularyCtrl.checkKeyUp($event)" type="text" />
</form>
Controller:
.controller('VocabularyCtrl', [
'$scope',
'$location',
function($scope, $location) {
this.checkChange = function () {
console.log("answer change: " + this.answer);
};
this.checkKeyUp = function ($event) {
console.log("answer keyUp: " + this.answer);
};
$scope.$watch('vocabularyCtrl.answer', function (answerNew, answerOld) {
console.log('answerOld: ' + answerOld + ', answerNew: ' + answerNew);
}, true);
};
]);
Example:
Input: ㄱ
Console:
answerOld: , answerNew:
answer keyUp:
Input: 가
Console:
answerOld: , answerNew:
answer keyUp:
Input: 감 (character is now fully composed)
Console:
answerOld: , answerNew:
answer keyUp:
Input: 감ㅅ (starting the next character, same behaviour with space bar)
Console:
answerOld: 감, answerNew:
answer change: 감
answer keyUp: 감