Created
May 9, 2014 10:52
-
-
Save yaegaki/6a9326686f492e614732 to your computer and use it in GitHub Desktop.
AngularJSでngModelをinputに付けたときに日本語入力がリアルタイムで反映されない問題 ref: http://qiita.com/yaegaki/items/c9cf111ef9d0c541a194
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input ng-model="hoge" type="text"> | |
<h1>{{hoge}}</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.directive('jpNgModel', function($parse){ | |
return { | |
restrict:'A', | |
link:function(scope, element, attrs){ | |
var getter = $parse(attrs.jpNgModel); | |
var setter = getter.assign; | |
var value = getter(scope); | |
element.bind('input', function(){ | |
setter(scope, element.val()); | |
scope.$apply(); | |
}); | |
scope.$watch(attrs.jpNgModel, function(n){ | |
if(n !== element.val()){ | |
element.val(n); | |
} | |
}); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input jp-ng-model="hoge" type="text"> | |
<h1>{{hoge}}</h1> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment