Thought & </code>


  • Home

  • Categories

  • About

  • Archives

  • Tags

  • Search

Angular2 Form: Get Specific Error Type for Multiple Validators

Posted on 2017-01-26   |   In Angular , Form   |  
Angular2 Form Get Specific Error Type for multiple validators
Read more »

ngModel in FormGroup

Posted on 2017-01-26   |   In Angular , Form   |  

In short ngModel can't be used by itself within FormGroup

1
2
3
<div [formGroup]="myGroup">
<input name="firstName" [(ngModel)]="firstName">
</div>

The above code will throw an error like

1
TypeError: Cannot set property stack of [object Object] which has only a getter at assignAll

Why ? kara@Github explained it very well at Github

formGroup expects you to create your own FormControl instances, whereas ngModel creates FormControl instances implicitly for you. You can't have two conflicting FormControl instances on the same form control element. When you use formControlName, ngModel does not activate or create a control (it's simply used as an @Input). formControlName just links to the existing input you created in your class.

karaGithub

Therefore, to make above code work, here is the correct code

1
2
3
4
<div [formGroup]="myGroup">
<input formControlName="firstName" [(ngModel)]="firstName">
</div>

How to analyze your HDD usage

Posted on 2017-01-20   |   In Tools , Tips   |  
How to analyze your HDD usage
Read more »

Clean Windows Installer to free up your HDD

Posted on 2017-01-20   |   In Tools , Tips   |  
Clean Windows Installer to free up your HDD
Read more »

Include and Exclude in Webpack Loader

Posted on 2017-01-09   |   In Webpack , loader   |  
Include and Exclude in webpack loader
Read more »
123…10
Sam Lin

Sam Lin

48 posts
37 categories
56 tags
RSS
© 2012 - 2017 Sam Lin
Powered by Hexo
NexT.Mist