简体   繁体   中英

Binding an Angular 2 array in the template

I have a component that looks something like this:

import {Component, Input} from "@angular/core";
@Component({
  selector : 'radio-select',
  ...
})
export class RadioToggleSelect {
  @Input() options : Array<string>;
}

Now I'd like to bind to the array in the HTML, such as something like:

 <radio-select options='["Users", "Account Holders"]'> </radio-select>

Is this possible?

Without [] the value is treated as plain string. Use this instead:

<radio-select [options]='["Users", "Account Holders"]'> </radio-toggle-select>

In Angular 2 For Property Binding target property should be surrounded its name with [] , which is one way binding from model to view. it should be as below

[options]='["Users", "Account Holders"]'

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