JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app>
<h2>入力中にEnterで[result]に表示します。</h2>
<div ng-controller="MyCtrl">
↓変換候補決定のEnterもキャッチ<br>
<input ng-model="inputText1" ng-keyup="pushEnter1($event)" type="text"/>
<br><br>
↓変換候補決定のEnterはキャッチしない<br>
<input id="myInput" ng-model="inputText2" ng-keyup="pushEnter2($event)" type="text"/>
<br><br>
result: {{message}}
</div>
</div>
JavaScript
function MyCtrl($scope) {
var compositionJustEnd = false;
var myInput = document.querySelector('#myInput');
myInput.addEventListener('compositionend', function(){
compositionJustEnd = true;
});
$scope.inputText = '';
$scope.pushEnter1 = function(e){
if(e.keyCode === 13){
$scope.message = $scope.inputText1;
$scope.inputText = '';
}
}
$scope.pushEnter2 = function(e){
// 変換候補を決定するためのEnterだったら無視
if(e.keyCode === 13 && !compositionJustEnd){
$scope.message = $scope.inputText2;
$scope.inputText = '';
} else {
compositionJustEnd = false;
}
}
}