angular2-ngmodel

Empty variable gives true value to disabled attribute on input

China☆狼群 提交于 2021-01-27 13:21:36
问题 I dont know if this is a problem or normal behavior. If we have a form like this: <form #form="ngForm" > <div> <label>field1</label> <input type="text" name="field1" [(ngModel)]="mainVar" [disabled]="someVar" /> </div> <div> <label>field2</label> <input type="text" name="field2" [(ngModel)]="someVar" /> </div> </form> In the same time variables mainVar and someVar are set to empty string in the component: mainVar = ''; someVar = ''; This will result in input with name field1 being disabled,

How to give correct path names for loadchildren in lazy loading angular 2 NgModule?

为君一笑 提交于 2020-01-03 16:44:56
问题 How to give correct path names for loadchildren in app-routing.module file in the angular 2 ngmodule, I followed the ngmodule concept in angular main website but its not giving such informations. I am getting the issue with app-routing.module paths,what i need to specify in the path names, with this issue, lazy loading is not working.all files are loading once yet a time ,can anyone help ? what i miss in the paths loadchildrens ? followed this Angular NgModule app-routing.module file. import

Angular 4 - How to use currency pipe in input type

♀尐吖头ヾ 提交于 2020-01-01 04:59:40
问题 I have an HTML input: <input [(ngModel)]="item.value" name="inputField" type="text" /> 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 it's giving me desirable output for the first time and showing error while updating the field: <input type="text" [ngModel]="item.value | currency:'USD':true" (ngModelChange)="item.value=($event)"> The above code leads to following error. ERROR Error

select list set selected item angular 2 ngModel

假装没事ソ 提交于 2019-12-21 16:53:27
问题 This is my current code: <select name="role" [(ngModel)]="user.role"> <option *ngFor="let role of roles" [ngValue]="role" [attr.selected]="role == user.role ? 'true' : 'false'">{{role.name}}</option> </select> I'm loading all the roles in an array, and the user class has a Role attribute (which is not loaded like user.role = roles[0] but just through the backend data). The problem is that the selected attribute is not working, and my select is not going to the correct role. What am I doing

Set default select list value Angular2

走远了吗. 提交于 2019-12-20 04:23:46
问题 I want to set the default option for the select in angular 2 as "Select an option". Here is the code that I have so far: HTML <div class="form-group"> <label class="col-md-4 control-label" for="CustomFix">Select an option:</label> <div class="col-md-4"> <select id="example" name="example" class="form-control" [(ngModel)]="exampleArray" (ngModelChange)="changes()"> <option disabled selected>Select a Custom Fix</option> <option *ngFor="let example of exampleArray" [ngValue]="example">{{example

Angular2 ngModelChange previous value

柔情痞子 提交于 2019-12-18 11:03:34
问题 Is there a way to get the previous(last) value of a field on ngModelChange? What I have goes something like this HTML <input type="text" [(ngModel)]="text" (ngModelChange)="textChanged($event)"> Handler private textChanged(event) { console.log('changed', this.text, event); } What I get is changed *newvalue* *newvalue* Of course I can keep the older value using another variable, but is there a better way? 回答1: What you can do is, DEMO : http://plnkr.co/edit/RXJ4D0YJrgebzYcEiaSR?p=preview

Angular 2: Using pipes with ngModel

ぐ巨炮叔叔 提交于 2019-12-18 04:12:49
问题 I was using JQuery inputmask in one of my forms along with [(ngModel)] , but for some reason they won't work together. Using either one by itself works perfectly fine, but combining the two completely breaks [(ngModel)] and new inputs don't get sent back to the component. After struggling with this for a while I figured using Angular 2's pipes would be a good solution, however I can't figure out how to get those two to work together either. Here is some code I am using for testing my pipe

Angular2 ngModel inside of ngFor

坚强是说给别人听的谎言 提交于 2019-12-18 02:42:58
问题 I am trying to bind an array of strings from my inputs, so in the html file I wrote this: <div *ngFor="let word of words; let in=index" class="col-sm-3"> <div class="form-group"> <input type="text" [(ngModel)]="words[in]" class="form-control" [attr.placeholder]="items[in]" required> </div> </div> But this didn't work as expected because when I log the words variable it show an empty array as initialized in my Component class. Also, I log the variable from another component should that

Angular2 Dynamic input field lose focus when input changes

左心房为你撑大大i 提交于 2019-12-17 05:01:42
问题 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 = fieldType;} } I have a function in my component which adds a new value to the field. addValue(field){ field.values.push(""); } The values and the button are displayed like this in my HTML. <div id="dropdown-values" *ngFor="let value of field.values; let j=index"> <input type=

Angular2 is there a way to use a two way binding with a checkbox?

可紊 提交于 2019-12-12 12:49:13
问题 I want to use a two way binding for a checkbox, but if I use the [(ngModel)] it is showing true or false instead of the value of the checked item. Does anybody know how this is done? If i want to use a two way binding and set it to "expression.value" in my case how do i do that: <input type="checkbox" type="checkbox"/> Option 1</a></li> I would like to bind the value of the checkbox in this case: Option 1 into the expression class. 回答1: This is a known issue https://github.com/angular/angular