I have form
with dynamic inserted input
to the DOM (from some other plugin). Is there way to read value from this input without ng-model on it?
<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
... :(
Because no built-in HTML element follows the x value and xChange event pattern, two-way binding with form elements requires NgModel .
standalone: When set to true, the ngModel will not register itself with its parent form, and acts as if it's not in the form.
The ngModel directive is a directive that is used to bind the values of the HTML controls (input, select, and textarea) or any custom form controls, and stores the required user value in a variable and we can use that variable whenever we require that value. It also is used during form validations.
The answer is: (ngModel) causes a 1-way data-binding, whereas [(ngModel)] ensures a two-way data binding.
AngularJS ng-model Directive. The ng-model directive binds the value of HTML controls (input, select, textarea) to application data.
Form contains multiple html input elements to take input from the user. button allows the user to submit the from to backend API an d it calls click binding event. In Angular, View is html template and controller is an typescript component. Reading input text is basic concept every Angular developer need to know.
<input [ngModel]="variable" (ngModelChange)="function_to_fire_on_model_change ($event)"> If you want to get the input value, but without ngModel (as in your snipet you don't use it), you can get as this: <input type="text" #input class="form-control" placeholder="Let's find your product....."
AngularJS can validate input data. AngularJS offers client-side form validation. AngularJS monitors the state of the form and input fields (input, textarea, select), and lets you notify the user about the current state. AngularJS also holds information about whether they have been touched, or modified, or not.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With