angular-forms

Angular2 If ngModel is used within a form tag, either the name attribute must be set or the form

▼魔方 西西 提交于 2019-11-26 18:54:19
问题 I am getting this error from Angular 2 core.umd.js:5995 EXCEPTION: Uncaught (in promise): Error: Error in app/model_exposure_currencies/model_exposure_currencies.component.html:57:18 caused by: 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}"> <td

AngularJS custom form component / directive using ng-model

半腔热情 提交于 2019-11-26 18:01:27
Angular custom form component / directive and $dirty property When using regular input, such as <form name="myForm"> <input type="text" ng-model="foobar"> </form> after typing in the input box myForm.$dirty is true. I'd like to create a simple directive such as angular.module('myModule', []) .directive('myDirective', function() { return { restrict: 'E', scope: { fooBar: '=' }, template: '<div><button ng-click="fooBar=foo"></button><button ng-click="fooBar=bar"></button></div>' }; }); Sample usage would be <form name="myForm"> <my-directive foo-bar="myObj.foobarValue"></my-directive> </form>

Differences between value and ngValue in Angular 5

a 夏天 提交于 2019-11-26 16:42:59
问题 Today I realized about an unexpected (for me) behaviour of the reactive forms in Angular 5. The server was receiving from the app an string with the value "null" instead of the null value, whichh is what I wanted. I did the following test: https://stackblitz.com/edit/angular-rjrspr?file=app%2Fapp.component.html As you can see in the picture below, if I use [value]="null" in the select, the field is getting "null" (string literal) as value. However, if I use [ngValue]="null" it gets the

Get access to FormControl from the custom form component in Angular

江枫思渺然 提交于 2019-11-26 09:07:52
问题 I have a custom form control component in my Angular application, which implements ControlValueAccessor interface. However, I want to access the FormControl instance, associated with my component. I\'m using reactive forms with FormBuilder and providing form control using formControlName attribute. SO, how do I access FormControl instance from inside of my custom form component? 回答1: This solution was born from the discussion in the Angular repository. Please, make sure to read it or even

AngularJS custom form component / directive using ng-model

痞子三分冷 提交于 2019-11-26 06:50:00
问题 Angular custom form component / directive and $dirty property When using regular input, such as <form name=\"myForm\"> <input type=\"text\" ng-model=\"foobar\"> </form> after typing in the input box myForm.$dirty is true. I\'d like to create a simple directive such as angular.module(\'myModule\', []) .directive(\'myDirective\', function() { return { restrict: \'E\', scope: { fooBar: \'=\' }, template: \'<div><button ng-click=\"fooBar=foo\"></button><button ng-click=\"fooBar=bar\"></button><