我正在尝试将数据传递给组件,看来我只能传递字符串,有没有一种方法可以使角度将数据输入识别为对象数组
组件html:
<app-mycomponent
url="https://url.com/getall"
data ="[{ name: 'a', required: ture},
{ name: 'b', required: false}]"
></app-mycomponent>
ts分量:
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-mycomponent',
templateUrl: './component.component.html',
})
export class HelloComponent {
@Input() url: string;
@Input() data : any;
}
答案 0 :(得分:0)
您必须使用one-way data-binding [data]
:
<app-mycomponent
url="https://url.com/getall"
[data] ="[{ name: 'a', required: true},
{ name: 'b', required: false}]">
</app-mycomponent>