[英]AngularJs Custom directive not binding with “textarea”
I make a custom directives for prevent enter key. 我为防止输入键制定了自定义指令。 It work fine for only "input" element, but it's not binding on "textarea". 它仅对“输入”元素有效,但对“文本区域”没有约束。 here is my js 这是我的js
function inputFocus() {
return {
restrict: 'E',
require: '?ngModel',
link: function ($scope, elem, attrs) {
elem.bind('keydown', function (event) {
var code = event.keyCode || event.which;
if (code === 13) {
$scope.$apply(function () {
$scope.$eval(attrs.inputFocus);
});
event.preventDefault();
}
});
}
}
}
And: 和:
<textarea class="form-control" name="UserName" maxlength="50" rows="2"
ng-model="UserName" tabindex="2" required>
</textarea>
I found my mistake by asking your question :) I give directives name by "input" so that it bind with all input elements. 我通过问您的问题发现了我的错误:)我通过“输入”给指令名称,以便它与所有输入元素绑定。 So, have to bind this also with "textarea" like 因此,也必须将其与“ textarea”绑定
angular.module('apanelApp').directive('textarea', inputFocus);
Thanks to all for response. 感谢所有人的回应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.