【发布时间】:2021-07-28 08:50:16
【问题描述】:
ChildComponent.ts
export class ChildComponent implements OnInit {
@Input() name?: string;
@Input() email?: string;
// A lot more props
constructor() {}
ngOnInit(): void {}
}
ParentComponent.ts
export class ParentComponent implements OnInit {
childProps = {
name: "johnny",
email: "johnny@gmail.com"
};
constructor() {}
ngOnInit(): void {}
}
ParentComponent.html
这行得通:
<app-child [name]="childProps.name" [email]="childProps.email"></app-child>
但是如何使用 ES6 扩展运算符传递所有道具?
<app-child [*]="{...childProps}"></app-child>
【问题讨论】:
-
Angular template syntax 不支持 。
-
嗯...大多数其他 Web 框架都支持这一点
-
我并不是说他们没有,只是 Angular 没有。参见例如stackoverflow.com/q/47297089/3001761,stackoverflow.com/q/58116963/3001761,stackoverflow.com/q/53845004/3001761。另请注意,AngularJS 完全是一个不同的框架。
-
谢谢@jonrsharpe
标签: angular typescript