0
我对Angular相对来说比较新,并且在我想出一个办法来解决这个问题之前遇到了严重的问题。 使用这个链接预览解决方案我将如何动态地填充ng2-smart-table的角度4
<https://plnkr.co/edit/OtJI13uA89caf8TG5lbI?p=preview>?
我对Angular相对来说比较新,并且在我想出一个办法来解决这个问题之前遇到了严重的问题。 使用这个链接预览解决方案我将如何动态地填充ng2-smart-table的角度4
<https://plnkr.co/edit/OtJI13uA89caf8TG5lbI?p=preview>?
要dymanically填充您的NG2智能表,你可以按照下面的步骤。 1.在你的模块中导入智能表组件。 从“ng2-smart-table”导入{LocalDataSource};
2.将以下代码添加到您的类中。
@Component({
selector: 'my-app',
template: `
<div>
<h2>Hello {{name}}</h2>
<button (click)="addColumn()">Add Column</button>
<ng2-smart-table [settings]="settings" [source]="source"></ng2-smart-table>
</div>
`,
})
export class ResultComponent implements OnInit
{
source: LocalDataSource;
i = 0;
settings;
mySettings = {
mode: 'inline',
actions: {
delete:false,
},
add: {
confirmCreate: true,
},
delete: {
confirmDelete: true,
},
edit: {
confirmSave: true,
},
columns: {
}
};
//method that adds the column. You can use trigger events to do this
public addColumn() {
this.mySettings.columns["new column " + this.i] = { title: 'new column
' + this.i.toString()};
this.settings = Object.assign({}, this.mySettings);
this.i++;
}
}