【发布时间】:2019-02-05 23:55:44
【问题描述】:
我正在开发一个使用 Angular 和 Ag-Grid 的应用程序。
我有一个如下定义的列:
columnDefs = [
...
{
headerName: 'LANG', field:'lang',
autoHeight: true,cellClass: 'cell-wrap-text',sortable: false, filter: true, editable: true,
cellEditor : 'agSelectCellEditor',
cellEditorParams : ['English', 'Spanish', 'French', 'Portuguese', '(other)'];
},
...
];
所以一切正常,在编辑模式下,我得到了带有不同选项的组合框('English'、'Spanish'、'French'、'Portuguese'、'(other)')。 我的问题是我需要获得调用 REST WS 的那些选项。
所以我尝试在我的组件(optionValues)中定义一个变量,并像这样在“ngOnInit”方法中填充它:
optionValues : any;
columnDefs = [
...
{
headerName: 'LANG', field:'lang',
autoHeight: true,cellClass: 'cell-wrap-text',sortable: false, filter: true, editable: true,
cellEditor : 'agSelectCellEditor',
cellEditorParams : this.optionValues,
},
...
];
ngOnInit(){
this.optionValues = this.http.get('http://localhost:8002/myservice');
}
但它不起作用,这里有什么问题?我必须使用其他方法吗?
你能帮帮我吗?
【问题讨论】:
-
this.http.get 不返回数组,需要订阅
-
谢谢您的回复,可以举个例子吗?
-
this.http.get('http://localhost:8002/myservice').subscribe(v=>this.optionValues=v) -
没有任何变化,它看起来方法 ngOnInit() 没有效果,在控制台中我看到这个警报:“ag-Grid: no values found for select cellEditor”
-
你可以为你的问题创建一个堆栈闪电战吗?