0
0
Angularframework~20 mins

Inline vs external templates in Angular - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Template Mastery in Angular
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
Difference in template rendering between inline and external templates
Consider two Angular standalone components. One uses an inline template, the other uses an external template file. What is the main difference in how Angular processes these templates during build and runtime?
Angular
Component A:
@Component({
  selector: 'app-inline',
  template: `<p>Inline template works!</p>`,
  standalone: true
})
export class InlineComponent {}

Component B:
@Component({
  selector: 'app-external',
  templateUrl: './external.component.html',
  standalone: true
})
export class ExternalComponent {}
ABoth inline and external templates are compiled and bundled identically with no difference in loading behavior.
BInline templates are compiled directly into the component code, while external templates are loaded asynchronously at runtime.
CExternal templates are compiled into the component code, but inline templates are fetched over HTTP at runtime.
DInline templates require a separate HTTP request during runtime, external templates are embedded in the component code.
Attempts:
2 left
💡 Hint
Think about how Angular bundles templates during build.
📝 Syntax
intermediate
1:30remaining
Correct syntax for inline template in Angular standalone component
Which of the following is the correct way to define an inline template in an Angular standalone component?
A@Component({ selector: 'app-test', template: `<h1>Hello</h1>`, standalone: true }) export class TestComponent {}
B@Component({ selector: 'app-test', templateUrl: `<h1>Hello</h1>`, standalone: true }) export class TestComponent {}
C@Component({ selector: 'app-test', template: './test.component.html', standalone: true }) export class TestComponent {}
D@Component({ selector: 'app-test', templateUrl: './test.component.html', standalone: true }) export class TestComponent {}
Attempts:
2 left
💡 Hint
Inline templates use the 'template' property with backticks for multi-line HTML.
🔧 Debug
advanced
2:00remaining
Why does this external template fail to load?
An Angular standalone component uses an external template file, but the app shows a 404 error for the template URL. What is the most likely cause?
Angular
@Component({
  selector: 'app-error',
  templateUrl: './missing-template.html',
  standalone: true
})
export class ErrorComponent {}
AThe selector name is invalid and causes the template not to load.
BAngular does not support external templates in standalone components.
CThe component must use 'template' instead of 'templateUrl' for standalone components.
DThe template file path is incorrect or the file is missing from the build output.
Attempts:
2 left
💡 Hint
Check the file path and build configuration.
state_output
advanced
2:30remaining
Rendered output difference between inline and external templates
Given these two Angular components, what will be the rendered output in the browser for each?
Angular
Inline component:
@Component({
  selector: 'app-inline',
  template: `<p>{{ message }}</p>`,
  standalone: true
})
export class InlineComponent {
  message = 'Hello from inline!';
}

External component:
@Component({
  selector: 'app-external',
  templateUrl: './external.component.html',
  standalone: true
})
export class ExternalComponent {
  message = 'Hello from external!';
}

// external.component.html content:
// <p>{{ message }}</p>
ABoth components show 'Hello from inline!'
BInline component shows 'Hello from inline!'; External component shows 'Hello from external!'
CInline component shows 'Hello from external!'; External component shows 'Hello from inline!'
DBoth components show empty paragraphs because templates are not compiled.
Attempts:
2 left
💡 Hint
Each component uses its own message property bound in the template.
🧠 Conceptual
expert
3:00remaining
Performance implications of inline vs external templates in Angular
Which statement best describes the performance impact of using inline templates compared to external templates in Angular standalone components?
AExternal templates always perform better because they are cached separately by the browser, unlike inline templates.
BInline templates reduce HTTP requests and can improve initial load time, but increase bundle size; external templates keep bundle size smaller but add HTTP requests.
CThere is no performance difference between inline and external templates because Angular treats them identically.
DInline templates cause Angular to recompile templates at runtime, slowing down the app compared to external templates.
Attempts:
2 left
💡 Hint
Consider network requests and bundle size trade-offs.