Q1. What is a template in Angular?
A template is an HTML file (or inline HTML) that defines the view of a component.
Templates can include data bindings, directives, and custom components.
They are written in enhanced HTML with Angular-specific syntax.
Angular compiles templates into JavaScript for efficient rendering.
Templates can include data bindings, directives, and custom components.
They are written in enhanced HTML with Angular-specific syntax.
Angular compiles templates into JavaScript for efficient rendering.
Q2. What is interpolation in Angular?
Interpolation is a one-way data binding technique that embeds component properties into the template using double curly braces {{ expression }}.
The expression is evaluated and converted to a string.
Example:
The expression is evaluated and converted to a string.
Example:
Hello {{ name }}!
Interpolation can also contain simple expressions like {{ 1 + 1 }}.Q3. What expressions are allowed in interpolation?
Interpolation can contain any JavaScript expression that doesn''t have side effects, such as: arithmetic ({{ a + b }}), ternary ({{ condition ? ''yes'' : ''no'' }}), method calls ({{ getName() }}), and property access ({{ user.name }}).
It cannot include assignments, new operators, or chained statements.
It cannot include assignments, new operators, or chained statements.
Q4. How do you use template reference variables?
Template reference variables (#var) give a name to a DOM element or directive within the template.
They can be used elsewhere in the template.
Example:
They can be used elsewhere in the template.
Example:
Q5. What is the difference between template and templateUrl?
The template property is used to define inline HTML as a string.
templateUrl points to an external HTML file.
Use template for small templates, and templateUrl for larger ones.
Both achieve the same result, but keeping templates in separate files improves maintainability.
templateUrl points to an external HTML file.
Use template for small templates, and templateUrl for larger ones.
Both achieve the same result, but keeping templates in separate files improves maintainability.
