Created
May 13, 2022 17:31
-
-
Save twerske/4f9f18f748584abd8edc3e608482922d to your computer and use it in GitHub Desktop.
Typed Angular Forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cat = new FormGroup({ | |
name: new FormGroup({ | |
first: new FormControl('Barb'), | |
last: new FormControl('Smith'), | |
}), | |
lives: new FormControl(9), | |
}); | |
// Type-checking for forms values! | |
// TS Error: Property 'substring' does not exist on type 'number'. | |
let remainingLives = cat.value.lives.substring(1); | |
// Optional and required controls are enforced! | |
// TS Error: No overload matches this call. | |
cat.removeControl('lives'); | |
// FormGroups are aware of their child controls. | |
// name.middle is never on cat | |
let catMiddleName = cat.get('name.middle'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment