Angular v21 improves forms handling and dependency injection for better scalability and cleaner code.
#Reactive Forms
import { FormControl, FormGroup } from '@angular/forms';
const loginForm = new FormGroup({
username: new FormControl(''),
password: new FormControl(''),
});
Listen to value changes:
loginForm.valueChanges.subscribe((value) => console.log(value));
#Optional Injectors
import { inject, Optional } from '@angular/core';
const myService = inject(MyService, { optional: true });
#Dependency Injection Tokens
bootstrapApplication(AppComponent, {
providers: [{ provide: API_URL, useValue: 'https://api.example.com' }],
});
#Forms + Signals
const username = signal('');
const password = signal('');
function login() {
console.log(username(), password());
}
#Conclusion
Angular v21 streamlines reactive forms and dependency injection, making apps more maintainable, scalable, and type-safe.