简体   繁体   English

在模板中绑定Angular 2数组

[英]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: 现在,我想绑定到HTML中的数组,例如:

 <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. 在Angular 2 For Property Binding中,目标属性的名称应用[]包围,这是从模型到视图进行绑定的一种方式。 it should be as below 它应该如下

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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