【发布时间】:2018-08-13 15:36:07
【问题描述】:
我有一个我创建的组件及其称为选项,因为它呈现编辑和删除按钮。然后我有一个可重用的表格组件。我将表格组件注入到站点上的视图中。然后我导入选项组件,但我没有在该视图上显示它,因为我想将它传递给表格组件并将其呈现给标记。是否可以将选项组件从主组件传递到表组件并注入它,因为不是没有具有相同选项组件的表。
options.component.ts
@Component({
selector: 'options',
template: `
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary active">
<input type="radio" name="options" id="option" autocomplete="off" checked>Edit
</label>
<label class="btn btn-danger">
<input type="radio" name="options" id="option" autocomplete="off" checked>Delete
</label>
</div>`,
styles: []
})
export class OptionsComponent implements OnInit {
constructor() { }
ngOnInit() { }
}
main.component.ts
import { TableComponent } 'file location here';
import { OptionsComponent } 'file location here'; // Component is injected here and I want to pass it to <app-table></app-table>
@Component({
selector: 'app-main',
template:'<app-table [tableData]="LocationsList"></app-table>'
})
export MainComponent implements OnInit {
LocationsList: []; // list of locations
}
table.row.component.ts
@Component({
selector: 'app-table',
template: `
<ul>
<li *ngFor="let property of tableData">{{ property }}</li>
</ul>`,
})
export class TableComponent implements OnInit {
@Input() tableData: any[];
}
【问题讨论】:
-
请添加一些代码以更好地说明您当前的结构。
-
我更新了@zz
标签: angular components angular-components