简体   繁体   中英

How to set more than one props in Angular template?

React JSX

<div {...props}></div>

Vue

<div v-bind="$props"></div>

Angular

// how to do?

You decorate properties with the @Input() decorator on the component's class

@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

 <div *ngFor="let prop of props"> <p>{{prop}}</p> </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM