在Angular 7中,@Component装饰器中的template属性表示组件的模板。模板是一个包含HTML和Angular指令的字符串,用于定义组件的UI。
以下是一个示例代码,展示了如何在Angular 7中使用@Component装饰器中的template属性:
import { Component } from '@angular/core';
@Component({
selector: 'app-example',
template: `
Hello, Angular 7!
This is an example component.
`
})
export class ExampleComponent {
// Component logic here
}
在上面的示例中,@Component装饰器中的template属性指定了组件的模板。模板字符串中包含了一个h1标签和一个p标签,用于展示一些文本。
在应用中使用这个组件时,可以在其他组件的模板中使用
标签来引入这个组件,并展示它的模板内容。
请注意,模板内容可以是多行的,并且可以使用Angular的模板语法来插入动态数据、循环和条件语句等。