Questions tagged [angular-ngmodel]

Used in Angular.js - The ngModel directive binds an input, select, textarea (or custom form control) to a property on the scope using NgModelController, which is created and exposed by this directive.

The ngModel directive binds an <input /> ,<select>, <textarea> (or custom form control) to a property on the scope using NgModelController, which is created and exposed by this directive.

ngModel is responsible for:

Binding the view into the model, which other directives such as input, textarea or select require.

  • Providing validation behavior (i.e. required, number, email, url).
  • Keeping the state of the control (valid/invalid, dirty/pristine, validation errors).
  • Setting related css classes on the element (ng-valid, ng-invalid, ng-dirty, ng-pristine).
  • Registering the control with its parent form.

Note: ngModel will try to bind to the property given by evaluating the expression on the current scope. If the property doesn't already exist on this scope, it will be created implicitly and added to the scope.

More on: http://docs.angularjs.org/api/ng/directive/ngModel

1617 questions
559
votes
8 answers

What's the difference between ng-model and ng-bind

I'm currently learning AngularJS and am having difficulty understanding the difference between ng-bind and ng-model. Can anyone tell me how they differ and when one should be used over the other?
dubs
  • 6,511
  • 4
  • 19
  • 35
395
votes
21 answers

Angular error: "Can't bind to 'ngModel' since it isn't a known property of 'input'"

I'm using Angular 4 and I am getting an error in the console: Can't bind to 'ngModel' since it isn't a known property of 'input' How can I resolve this?
Vijay Kumar
  • 4,059
  • 3
  • 11
  • 6
283
votes
14 answers

Ng-model does not update controller value

Probably silly question, but I have my html form with simple input and button: {{ searchText }} Then in the controller (template and controller are called from…
alchemication
  • 5,084
  • 6
  • 22
  • 21
144
votes
9 answers

How to set a selected option of a dropdown list control using angular JS

I am using Angular JS and I need to set a selected option of a dropdown list control using angular JS. Forgive me if this is ridiculous but I am new with Angular JS Here is the dropdown list control of my html Here both of them…
LittleDragon
  • 2,317
  • 2
  • 18
  • 23
107
votes
2 answers

ngModel Formatters and Parsers

I posted the same question in different form, but no one answered. I am not getting a clear picture of what the Formatters and Parsers do in angular js. By the definition, both the Formatters and Parsers look similar to me. Maybe I am wrong, as I…
RONE
  • 5,415
  • 9
  • 42
  • 71
103
votes
10 answers

AngularJS : ng-model binding not updating when changed with jQuery

This is my HTML: When I type into the box, the model is updated via the 2-way-binding mechanism. Sweet. However when I do this via JQuery... $('#selectedDueDate').val(dateText); It…
Greg
  • 31,180
  • 18
  • 65
  • 85
66
votes
5 answers

Angularjs: select not updating when ng-model is updated

I've created the following example so you can see exactly what is happening: http://jsfiddle.net/8t2Ln/101/ The same thing happens if I use ng-options. I have a different reason for doing it this way, but for the simplification of the example left…
Jhorra
  • 6,233
  • 21
  • 69
  • 123
63
votes
7 answers

What is purpose of using forRoot in NgModule?

What is the purpose of using forRoot in NgModule? Is it same as the providers in AngularJS 1.x? How does it play the significant role in lazy loading? TIA.
Mantu Nigam
  • 3,690
  • 7
  • 24
  • 41
63
votes
13 answers

Angular bootstrap datepicker date format does not format ng-model value

I am using bootstrap date-picker in my angular application. However when I select a date from that date-picker underlying ng-model that I have bind gets updated I want that ng-model in one date format 'MM/dd/yyyy'. but it every times makes date like…
61
votes
6 answers

angular 6 warning for using formControlName and ngModel

I recently upgraded the angular version to 6-rc. I got following warning It looks like you're using ngModel on the same form field as formControlName. Support for using the ngModel input property and ngModelChange event with reactive form…
Akshay
  • 3,558
  • 4
  • 43
  • 77
58
votes
7 answers

Get user input from textarea

I'm new to angular2. I want to store user input from a text area in a variable in my component so I can apply some logic to this input. I tried ngModel but it doesn't work. My code for the textarea: