Questions tagged [angularjs-ng-model]

The ngModel directive in AngularJS 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:

  • Instantiating the ngModelController
  • 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, touched/untouched, validation errors).
  • Setting related CSS classes on the element (ng-valid, ng-invalid, ng-dirty, ng-pristine, ng-touched, ng-untouched) including animations.
  • Registering the control with its parent form.
  • Formatters, Parsers and View change listeners

Information from AngularJS API

See also

532 questions
292
votes
13 answers

ng-model for `` (with directive DEMO)

I tried to use ng-model on input tag with type file: But after selecting a file, in controller, $scope.vm.uploadme is still undefined. How do I get the selected file in my controller?
Endy Tjahjono
  • 24,120
  • 23
  • 83
  • 123
127
votes
9 answers

filters on ng-model in an input

I have a text input and I don't want to allow users to use spaces, and everything typed will be turned into lowercase. I know I'm not allowed to use filters on ng-model eg. ng-model='tags | lowercase | no_spaces' I looked at creating my own…
117
votes
8 answers

Difficulty with ng-model, ng-repeat, and inputs

I am trying to allow the user to edit a list of items by using ngRepeat and ngModel. (See this fiddle.) However, both approaches I've tried lead to bizarre behavior: one doesn't update the model, and the other blurs the form on each keydown. Am I…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
81
votes
7 answers

AngularJS: ng-model not binding to ng-checked for checkboxes

I referred to this before asking this question: AngularJs doesn't bind ng-checked with ng-model If ng-checked is evaluated to true on the html side, the ng-model is not updated. I can't ng-repeat as suggested in the above question because I have to…
Abilash
  • 6,089
  • 6
  • 25
  • 30
51
votes
2 answers

Angular CLI - Please add a @NgModule annotation when using latest

note: I'm new to Angular, so please excuse any new comer stupidity here. Details I've installed the latest version of Angular CLI The default app loads and runs perfectly fine after 'ng serve' Issue I decided to create a new module an import it…
MegaTron
  • 3,133
  • 6
  • 28
  • 45
44
votes
5 answers

What's the difference/incompatibility between ng-model and ng-value?

As far as i understood ng-model sets the value for that particular element in which the model is been assigned. given that how is ng-value different from ng-model?
33
votes
5 answers

AngularJS number input formatted view

I want to use a formatted number input to show thousand seperator dots to user when he types big numbers. Here is the directive code that I used: http://jsfiddle.net/LCZfd/3/ When I use input type="text" it works, but when I want to use input…
Murat Çorlu
  • 8,207
  • 5
  • 53
  • 78
28
votes
3 answers

Angular Checkboxes "Select All" functionality with only one box selected initially

I have a form that contains 3 checkboxes: "Select All", "Option 1", and "Option 2".
Select all
Option 1 …
Cumulo Nimbus
  • 8,785
  • 9
  • 47
  • 68
21
votes
6 answers

Angularjs select does not mark matching model as selected

I have a problem with my ngModel in select not showing as selected. Both id and name are matching but its not working, see selectedState. Pointing model to the actual object within options array works, see selelectedState2. No idea whats going on…
Micor
  • 1,502
  • 4
  • 20
  • 39
16
votes
5 answers

AngularJS - ng-model fails on contenteditable

I'm learning AngularJS. I've come across something I can't explain, nor can I find any explanation for (or solution). I have a simple AngularJS app and I am attempting to bind a to a value, but it doesn't work. …
Alex McMillan
  • 17,096
  • 12
  • 55
  • 88
15
votes
4 answers

AngularJS 1.4: Select List Value not Initializing Correctly when List is Inserted with $compile

Here's some quick background info. I just upgraded to Angular 1.4. I'm using an API written in C# for my server-side calls. A section of my page shows 2 select lists (Project & Sub-project). Both are supposed to default to "(Select a ______)", which…
14
votes
1 answer

AngularJS - Access child directive controller

How to access the child directive controllers? Specifically, I need to access all ngModelController(s) which are present inside a parent directive. Example:
11
votes
4 answers

ng-checked and ng-change radio button not work together - angularjs

http://plnkr.co/edit/RP9SpO1qGjn5Ua6pZJ3D?p=preview js angular.module("sampleapp", []).controller('samplecontroller', function($scope,$rootScope) { $scope.radii = [ {id:.25, checked:false, name:"1/4 Mile"}, {id:.5, checked:false, name:"1/2…
10
votes
2 answers

How do I get an input value into Angular's $scope?

I'm new to Angular, and I am trying to do something really basic. Here is a part of a view (all angular files are added elsewhere) :
And here is my controller : …
Arhyaa
  • 369
  • 1
  • 3
  • 21
10
votes
1 answer

Angular using $index in ng-model

I have the following loop in which I'm trying to increment several fields based on the array index each time through the loop.
byrdr
  • 5,197
  • 12
  • 48
  • 78
1
2 3
35 36