How can you set default values for form controls in a template-driven form?
- Use the defaultValue attribute.
- Assign values directly in the template.
- Set values programmatically in the component.
- Use the ngDefaultControl directive.
In template-driven forms, default values for form controls are typically set programmatically in the component by initializing the corresponding form control variables with the desired default values. While you can assign values directly in the template, this doesn't allow for dynamic default values or interaction with the component logic. The other options mentioned are not common practices for setting default values in template-driven forms.
Loading...
Related Quiz
- Imagine you're building a custom tooltip directive in Angular. To ensure that the tooltip is positioned relative to the element it's attached to, you need to gain access to the host element. How would you achieve this?
- Which decorator is used to inject a service into an Angular component?
- How can you make a service optional for injection in a component?
- When ViewEncapsulation.Native is used, the styling is encapsulated using the browser's native ________.
- The @Output() decorator is used to emit custom ________ from a component.