[英]Angular: how to get input value without ng-model
I have form
with dynamic inserted input
to the DOM (from some other plugin). 我有一个动态插入
input
到DOM(来自其他一些插件)的form
。 Is there way to read value from this input without ng-model on it? 有没有办法在没有ng-model的情况下从这个输入中读取值?
<form name="myForm" data-my-directive>
<div class="customPlugin">
<!-- here input without ng-modeal appears: -->
[ <input type="text" name="foo" value="bar" /> ]
</div>
</form>
I look at many examples, but everywhere people writes about ng-model
... :( 我看了很多例子,但到处都有人写关于
ng-model
... :(
Use a directive that watches for changes. 使用监视更改的指令。
You can then assign this to your scope, if deemed necessary. 如果认为有必要,您可以将其分配给您的范围。
.directive('watchForChanges', function () {
return {
link: function(scope, element, attrs) {
element.on('change', function (e) {
console.log(e.target.value);
// scope.myValue = e.target.value;
})
}
}
});
PLNKR: http://plnkr.co/edit/qrj8ZbUya5wE0EylFcGG?p=preview PLNKR: http ://plnkr.co/edit/qrj8ZbUya5wE0EylFcGG?p = preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.