Javascript 用户在输入文本中键入逗号时Angularjs监视
问题在于,我想在用户键入时观察输入文本,当用户键入逗号时,输入将得到验证,而不是Javascript 用户在输入文本中键入逗号时Angularjs监视,javascript,angularjs,Javascript,Angularjs,问题在于,我想在用户键入时观察输入文本,当用户键入逗号时,输入将得到验证,而不是ng click=“action()” 我想要类似逗号类型的=“action()”,我尝试了ng change,scope.watch(),没有缺少 到目前为止,我所拥有的: <input id="tagInsert" type="text" name="newTag" ng-model="newTag" ng-model-options="{debounce: 100}" typeahead="tag for
ng click=“action()”
我想要类似逗号类型的=“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')" />
我也尝试过使用ng键控功能:
$scope.addInterestOnEvent = function (event) {
if (event.which !== 188) return;
event.preventDefault();
$scope.addInterest();
};
这是行不通的
编辑
它确实适用于
ng keydown=“action()”
我忘记重新启动服务器。您的$watch逻辑不正确。$watch用于查找模型值的更改。请参阅。$watch所做的只是在表达式更改时注册回调
$scope.$watch('newTag', function(nv,ov) {
if (nv!==ov ){
action();
}
});
在您的情况下,您必须编写指令并查找
,
您的$watch逻辑不正确。$watch用于查找模型值的更改。请参阅。$watch所做的只是在表达式更改时注册回调
$scope.$watch('newTag', function(nv,ov) {
if (nv!==ov ){
action();
}
});
在您的情况下,您必须编写指令并查找
,
创建非常简单的指令commaTyped
。创建非常简单的指令commaTyped
。