【发布时间】:2018-12-31 23:52:30
【问题描述】:
我正在查看一位同事的 Angular 代码,他在 Angular 方面比我知识渊博,努力了解更多信息。
真正让我困惑的一件事是在组件本身的 HTML 模板中使用组件的选择器。
widgetA.component.ts
import {
Component,
OnInit,
Input,
HostListener
} from '@angular/core';
// other imports here
@Component({
selector: 'widgetA',
templateUrl: './widgetA.component.html',
styleUrls: ['./widgetA.component.scss']
})
export class WidgetAComponent implements OnInit {
@Input() property1!: string;
@Input() property2: string;
// remainder of class here
}
widgetA.component.html
<div>
<!-- other HTML here -->
<widgetA
[property1]="value1"
[property2]="value2"
></widgetA>
<widgetB
[property3]="value3"
[property4]="value4"
></widgetB>
<!-- other HTML here -->
</div>
我不得不假设这是允许的,因为 webpack 成功编译了代码。我想我想知道这是否是典型的角度?它是一种设计模式吗?在组件本身的 HTML 模板中包含对组件的引用似乎让我感到困惑。
【问题讨论】:
标签: angular