Используйте переменную angular, как показано ниже title: string = "Content" Например, попробуйте, я создал образец класса MyComponent, как показано ниже.
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.css']
})
export class MyComponentComponent implements OnInit {
private myVariable:string="Hello World"
constructor() { }
ngOnInit() {
}
}
my-component.component. html
<p>
{{myVariable}}
</p>
Убедитесь, что добавили вышеуказанный компонент в app.component. html, который является компонентом начальной загрузки, как показано ниже
<app-my-component></app-my-component>
также в app.module, как показано ниже в разделе описания.
declarations: [
AppComponent,
TopBarComponent,
ProductListComponent,
MyComponentComponent
],
bootstrap: [ AppComponent ]