Angular 2's ngModel directive used for two-way databinding
Questions tagged [angular2-ngmodel]
200 questions
158
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…
![](../../users/profiles/3025289.webp)
Lonely
- 5,174
- 6
- 33
- 67
62
votes
2 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 =…
![](../../users/profiles/2794211.webp)
Elbbard
- 1,692
- 4
- 22
- 43
55
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…
![](../../users/profiles/1870747.webp)
movila
- 705
- 1
- 6
- 6
42
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…
![](../../users/profiles/5103858.webp)
Usman I
- 1,898
- 4
- 20
- 39
34
votes
4 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) {
…
![](../../users/profiles/3563146.webp)
irtaza
- 671
- 1
- 6
- 13
26
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…
![](../../users/profiles/5513078.webp)
majodi
- 518
- 1
- 6
- 16
22
votes
4 answers
How to show placeholder (empty option) in select control in Angular 2?
I have this code in my template:
In my…
![](../../users/profiles/1329461.webp)
Leantraxxx
- 4,206
- 3
- 33
- 52
16
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…
![](../../users/profiles/2018084.webp)
Juicy
- 9,942
- 32
- 97
- 181
15
votes
4 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": {
…
![](../../users/profiles/2414160.webp)
Sarath
- 1,131
- 4
- 18
- 35
15
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…
![](../../users/profiles/1987923.webp)
Ibraheem Al-Saady
- 806
- 2
- 13
- 28
14
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…
![](../../users/profiles/454252.webp)
allenhwkim
- 25,529
- 15
- 80
- 114
12
votes
2 answers
Angular 4 - How to use currency pipe in input type
I have an HTML input:
I want to format its value and use an existing pipe:
.... [(ngModel)]="item.value | currency:'USD':true" .....
Also I'm trying to use it the following way, but…
![](../../users/profiles/6650215.webp)
Mahendra Waykos
- 600
- 2
- 7
- 17
12
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…
![](../../users/profiles/5129407.webp)
mbucks
- 131
- 1
- 9
12
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…
![](../../users/profiles/6810805.webp)
Mike Kovetsky
- 1,398
- 1
- 12
- 22
12
votes
3 answers
Angular2 ngModel inside of ngFor
I am trying to bind an array of strings from my inputs, so in the html file I wrote this:
![](../../users/profiles/2511384.webp)
Mehdi Benmoha
- 2,992
- 3
- 18
- 37