[英]How to set more than one props in Angular template?
React JSX反应 JSX
<div {...props}></div>
Vue Vue
<div v-bind="$props"></div>
Angular Angular
// how to do?
You decorate properties with the @Input()
decorator on the component's class您使用组件的 class 上的@Input()
装饰器装饰属性
@Component({
template: 'someHtml',
selector: 'my-component'
})
class MyComponent() {
@Input() prop1;
@Input() prop2;
}
and set them in the template of the consuming component with property binding并使用属性绑定将它们设置在消费组件的模板中
<my-component [prop1]="someValue" [prop2]="anotherValue"></my-component>
If props is an array you can iterate with *ngFor如果 props 是一个数组,您可以使用 *ngFor 进行迭代
<div *ngFor="let prop of props"> <p>{{prop}}</p> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.