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 {}Both inline and external templates are compiled into JavaScript template functions during the build process and bundled identically. There is no difference in processing or loading behavior at runtime.
The 'template' property is used for inline HTML content. 'templateUrl' expects a string path to an external HTML file.
@Component({
selector: 'app-error',
templateUrl: './missing-template.html',
standalone: true
})
export class ErrorComponent {}Angular standalone components support external templates. A 404 error usually means the file path is wrong or the file was not included in the build output.
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>Each component binds its own 'message' property in its template. Inline or external template does not affect the binding output.
There is no significant performance difference between inline and external templates because Angular compiles both into JavaScript during the build process and bundles them identically.