import { bootstrapApplication } from '@angular/platform-browser';
import { Component, Injectable, inject } from '@angular/core';
@Injectable({ providedIn: 'root' })
class MessageService {
getMessage() { return 'Hello from a service!'; }
}
@Component({
selector: 'app-root',
standalone: true,
template: `<h1>{{ msg.getMessage() }}</h1>`
})
class App {
msg = inject(MessageService);
}
bootstrapApplication(App);
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Angular First App: Service</title>
</head>
<body>
<app-root></app-root>
</body>
</html>