Angular 2's ngModel directive used for two-way databinding
Questions tagged [angular2-ngmodel]
209 questions
189
votes
7 answers
Using Pipes within ngModel on INPUT Elements in Angular
I've an HTML INPUT field.
and I want to format its value and use an existing pipe:
....
[(ngModel)]="item.value | useMyPipeToFormatThatValue"
....
and get the error…
user3025289
70
votes
3 answers
Angular2 Dynamic input field lose focus when input changes
I'm making a dynamic form. A Field has a list of values. Each value is represented by a string.
export class Field{
name: string;
values: string[] = [];
fieldType: string;
constructor(fieldType: string) {this.fieldType =…

Elbbard
- 2,064
- 6
- 30
- 53
59
votes
3 answers
Angular 2 ngModel in child component updates parent component property
I made a simple UI which consist two components (parent and child).
What the UI does is that when I type some stuff in the input box of the Child component. The value will change using ngModel.
The child component works fine that way.
// Child…

movila
- 927
- 1
- 8
- 12
56
votes
1 answer
Angular - How can I write a condition in interpolation?
I have a table which is being populated through the add client form. It works fine and the changes are displayed. The thing is I have a select list in which a user selects the specific source and then it is saved in ngmodel. Here is the code.
Select…

Usman Iqbal
- 2,379
- 5
- 26
- 50
37
votes
6 answers
Angular2 ngModelChange previous value
Is there a way to get the previous(last) value of a field on ngModelChange?
What I have goes something like this
HTML
Handler
private textChanged(event) {
…

irtaza
- 721
- 1
- 6
- 13
27
votes
4 answers
Attribute directive with ngModel to change field value
I want to change (force) input field values while typing using a attribute Directive. With it I would like to create directives like uppercase, lowercase, maxlength, filterchar, etc. to be used on input fields on forms. I found this example: Angular…

majodi
- 536
- 1
- 7
- 17
22
votes
5 answers
How to show placeholder (empty option) in select control in Angular 2?
I have this code in my template:
In my…

Leantraxxx
- 4,506
- 3
- 38
- 56
19
votes
3 answers
Angular - [(ngModel)] vs [ngModel] vs (ngModel)
I currently understand that [(ngModel)]="expression" is two-way binding from component to view and vice versa. I also understand that [ngModel]="expression" is one-way binding (I believe from component to view?). Then there's the possibility of…

mbucks
- 201
- 1
- 2
- 9
19
votes
7 answers
Angular - There is no directive with "exportAs" set to "ngModel"
Following are the files in the AngularJS project. As suggested in some posts, I have added:
ngModel name="currentPassword" #currentPassword="ngModel
in the input field, but still getting an error.
package.json
.........
"dependencies": {
…

Sarath
- 1,438
- 4
- 24
- 40
18
votes
3 answers
Angular select option with selected attribute not working
Using Angular 4, I have a html template and I want a selection box with two options. One of those options should be pre-selected by default.

slanden
- 1,199
- 2
- 15
- 35
18
votes
1 answer
Binding the value in a textarea
I'm trying to do the simplest two way binding in Angular2. I would like to share a variable between my component and it's template.
My template is:
And my component is:
import { Component } from…

Juicy
- 11,840
- 35
- 123
- 212
16
votes
3 answers
angular2 pass ngModel to a child component
I have ParentComponent and a ChildComponent, and I need to pass the ngModel in ParentComponent to ChildComponent.
// the below is in ParentComponent template
how can I get the…

Ibraheem Al-Saady
- 854
- 3
- 14
- 30
16
votes
3 answers
angular2 access ngModel variable from a directive
I am trying to build a datetime picker directive like the following.
and date1 is assigned as a Date, e.g., new Date()
When I display this in html, text in input element looks like the…

allenhwkim
- 27,270
- 18
- 89
- 122
15
votes
3 answers
Angular2 - Prevent Checkbox from being checked
I have a table that contains a checkbox per row. In the table header, I have a Check All checkbox that toggles all of the table row boxes.
I am trying to implement some logic to where if the count of checkboxes are going to exceed a specific limit,…

SBB
- 8,560
- 30
- 108
- 223
14
votes
3 answers
Setting ngModel default value angular 2
Have a problem with ngModel in angular 2. Have a task to output a couple of inputs from an array in component class.
Discovered a possibility to make ngModel take its value from [name] attribute without embracing ngModel in [()]. And I wonder if…

Mike Kovetsky
- 1,638
- 1
- 14
- 24