【发布时间】:2016-04-14 11:31:23
【问题描述】:
一切都在问题中,我想在用户输入时观察输入文本,当他输入逗号时,输入得到验证而不是 ng-click="action()"
我想要 Comma-Typed="action()" 之类的东西,我尝试了 ng-change , scope.watch() 没有缺少..
到目前为止我所拥有的:
<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')" />
控制器:
$scope.$watch('newTag', function(val) {
if (val.keyCode == 188) { // KeyCode For comma is 188
alert('comma added');
action();
}
});
我也尝试过使用 ng-keydown :
$scope.addInterestOnEvent = function (event) {
if (event.which !== 188) return;
event.preventDefault();
$scope.addInterest();
};
这是行不通的。
编辑
它确实适用于 ng-keydown="action()" 是我忘记重新启动服务器。
【问题讨论】:
-
创建非常简单的指令
commaTyped。
标签: javascript angularjs