angular-ngmodel

Angular ng-value doesn't work with input radio

独自空忆成欢 提交于 2021-02-20 05:12:16
问题 I have 3 radio inputs bound to ctrl.poiType , where ctrl is the controller and poiType is an integer. ctrl.poiType can have one of the 3 values specified by four constants (ctrl.TYPE_TRIP, ctrl.TYPE_EVENT, ctrl.TYPE_POI). So I've created three input radio, using ng-model and ng-value like this: <label class="btn btn-default"> <input type="radio" autocomplete="off" ng-value="ctrl.TYPE_TRIP" ng-model="ctrl.poiType" ng-change="ctrl.alert()"/>itinerari </label> The radio should be checked if the

Angular ng-value doesn't work with input radio

亡梦爱人 提交于 2021-02-20 05:06:42
问题 I have 3 radio inputs bound to ctrl.poiType , where ctrl is the controller and poiType is an integer. ctrl.poiType can have one of the 3 values specified by four constants (ctrl.TYPE_TRIP, ctrl.TYPE_EVENT, ctrl.TYPE_POI). So I've created three input radio, using ng-model and ng-value like this: <label class="btn btn-default"> <input type="radio" autocomplete="off" ng-value="ctrl.TYPE_TRIP" ng-model="ctrl.poiType" ng-change="ctrl.alert()"/>itinerari </label> The radio should be checked if the

NgModelChange on input number not updating the view

∥☆過路亽.° 提交于 2021-02-11 15:21:30
问题 I'm currently trying to create an input number that prevent user to enter a number that is higher than a @Input() maxValue, I implemented it like this : HTML : <input class="number-selector-input" type="number" [(ngModel)]="value" (ngModelChange)="checkValue($event)" /> Typescript : public checkValue(value) { if (value > this.maxValue) { this.value = this.maxValue; } if (value < this.minValue) { this.value = this.minValue; } } It is working quite well but there is still a problem that I can't

Angular weirdness: how can one object attribute change an attribute on two different objects?

巧了我就是萌 提交于 2021-02-05 06:09:49
问题 I'm building a website using Angularjs in which I've got a list of objects: $scope.fieldsToShow = [ { "fields": {}, "type": "LOGGED_IN" }, { "fields": {}, "type": "PERSONAL", "user": 2, "name": "Rick Astley" } ]; I then select one of the objects into a variable: var $scope.currentObject = $scope.fieldsToShow[1]; to let the user change it using the some checkboxes: <input ng-model="currentObject.fields.a" type="checkbox"> which changes both $scope.currentObject : { "fields": { "a": true },

Angular weirdness: how can one object attribute change an attribute on two different objects?

自作多情 提交于 2021-02-05 06:08:53
问题 I'm building a website using Angularjs in which I've got a list of objects: $scope.fieldsToShow = [ { "fields": {}, "type": "LOGGED_IN" }, { "fields": {}, "type": "PERSONAL", "user": 2, "name": "Rick Astley" } ]; I then select one of the objects into a variable: var $scope.currentObject = $scope.fieldsToShow[1]; to let the user change it using the some checkboxes: <input ng-model="currentObject.fields.a" type="checkbox"> which changes both $scope.currentObject : { "fields": { "a": true },

ngModel's unexpected behavior inside Angular Form

微笑、不失礼 提交于 2021-01-29 20:19:48
问题 The following code will generate two inputs with same value bye (instead of hello and bye ). It would be great if someone could (theoretically) explain this behaviour and tell the exact cause. <form> <div *ngFor="let item of ['hello', 'bye'];"> <input name="name" [(ngModel)]="item"> </div> </form> Edit: To explain my question better: The reason couldn't be that because they are bind to the same object, they will have identical value. If that is so the following case would have the same value

Angular ngModel checks all checkboxes

不打扰是莪最后的温柔 提交于 2021-01-29 09:01:10
问题 Trying to check/uncheck all children checkboxes using ngModel and all checkboxes are checked, but also trying to check alone children and all checkboxes are always checked; <div> <input type="checkbox" [checked]="myVar1" (change)="myVar1 = !myVar1" /> Parent </div> <ul> <input type="checkbox" [(ngModel)]="myVar1" /> Child1<br> <input type="checkbox" [(ngModel)]="myVar1" /> Child2 </ul> Tried using [ngModelOptions]="{standalone: true}" property and it results with the same behaviour - all

Why do I need to mention name attribute or ngModelOptions=“{standalone: true}” while using ngModel?

瘦欲@ 提交于 2020-12-15 04:57:26
问题 I am working on an Angular Form. I have a domain model with some properties. I am binding them by using ngModel . During this, if I don't use name attribute then I get the below error. ERROR Error: If ngModel is used within a form tag, either the name attribute must be set or the form control must be defined as 'standalone' in ngModelOptions. Example 1: <input [(ngModel)]="person.firstName" name="first"> Example 2: <input [(ngModel)]="person.firstName" [ngModelOptions]="{standalone: true}">

Angular importing FormsModule in app.module vs child.module

[亡魂溺海] 提交于 2020-08-08 07:07:08
问题 I'm using Angular with lazy loading modules. Each component has its own module. If I import a module in the root module (app.module) it must work fine. For example, I imported HttpClientModule in app.module and can use it in child components. But about FormsModule , this doesn't work fine. I must import it in the child module, otherwise, I get the following errors: Can't bind to 'ngModel' since it isn't a known property of 'input'. (" Do you have any idea why this happens? 回答1: I found the