Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何使用REST调用的结果动态初始化CellEditor_Angular_Ag Grid - Fatal编程技术网

Angular 如何使用REST调用的结果动态初始化CellEditor

Angular 如何使用REST调用的结果动态初始化CellEditor,angular,ag-grid,Angular,Ag Grid,我正在开发一个使用Angular和Ag网格的应用程序 我有一个列定义如下: columnDefs = [ ... { headerName: 'LANG', field:'lang', autoHeight: true,cellClass: 'cell-wrap-text',sortable: false, filter: true, editable: true, cellEditor : 'a

我正在开发一个使用Angular和Ag网格的应用程序

我有一个列定义如下:

  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)'];


        },
       ...

        ];
所以一切都很好,在编辑模式下,我得到了带有不同选项的组合框(“英语”、“西班牙语”、“法语”、“葡萄牙语”、“其他”)。 我的问题是,我需要让这些选项调用REST WS

因此,我尝试在我的组件(optionValues)中定义一个变量,并用“ngonit”方法填充它,如下所示:

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');

}
但它不起作用,这里怎么了?我必须使用不同的方法吗


您能帮助我吗?

您可以在http中初始化网格设置

this.http.get(...).subscribe(v=>{
  this.gridOptions = {
    columnDefs: [...]
  };
  this.optionValues=v;
});

您可以在http中初始化网格设置

this.http.get(...).subscribe(v=>{
  this.gridOptions = {
    columnDefs: [...]
  };
  this.optionValues=v;
});

this.http.get不返回数组,您需要订阅它谢谢您的回复,能否提供一个示例?
this.http.get('http://localhost:8002/myservice“).subscribe(v=>this.optionValues=v)
没有任何更改,看起来方法ngOnInit()无效,在控制台中我看到此警报:“ag Grid:找不到select cellEditor的值”您能为您的问题创建stackblitz吗?this.http.get不返回数组,您需要订阅它谢谢您的回复,您能提供一个示例吗?
this.http.get('http://localhost:8002/myservice).subscribe(v=>this.optionValues=v)
没有任何变化,看起来ngOnInit()方法没有效果,在控制台中我看到此警报:“ag网格:找不到select cellEditor的值”您可以为您的问题创建stackblitz吗?我已经尝试过了,它对我有效。我不知道您是如何创建的,因此如果您可以创建stackblitz,我将查看一下,
cellEditorParams:{values:[…]}
用于当前ag网格使用arr.map(v=>v.description)let
arr=[{“id”:0,“code”:“E”,“description”:“English”},{“id”:1,“code”:“F”,“description”:“Frenh”}]
法语“}]