IT노트(구)/JavaScript
AngularJS ng-model에서 한글이 실시간 바인드가 되지 않을 때
스프링연구소
2015. 12. 21. 12:46
AngularJS에서 ng-model을 사용할 때
한글은 실시간 바인드가 되지 않는 경우가 있다.(영어는 잘 되는데!)
그럴 경우 kr-input 설정을 별도로 해주면
한글도 정상 처리가 된다!
다음과 같이 하면 된다!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 |
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp">
<p>한글도 실시간 처리 가능 : <input type="text" ng-model="name" kr-input></p> <!--kr-input 태그를 추가한다.-->
<p>반영 결과 : {{name}}</p>
</div>
<script>
var application = angular.module('myApp', [])
// 다음과 같이 kr-input 설정이 필요하다.
application.directive('krInput', ['$parse', function($parse) {
return {
priority : 2,
restrict : 'A',
compile : function(element) {
element.on('compositionstart', function(e) {
e.stopImmediatePropagation();
});
},
};
}]);
</script>
</body>
</html> |
cs |