简体   繁体   English

Angular 错误:错误:在 TS 中找不到具有 id 的列

[英]Angular Error: Error: Could not find column with id when it's in TS

In my app, I have a table with multiple columns.在我的应用程序中,我有一个包含多列的表。 I'm trying to fill it with the respected data but when the page opens I get the error Could not find column with id "PublishedParty" yet, it's in the TS file.我正在尝试用受尊重的数据填充它,但是当页面打开时,我收到错误Could not find column with id "PublishedParty" ,它在 TS 文件中。 Here is my code, what is wrong with it?这是我的代码,它有什么问题?

HTML: HTML:

<ng-container *ngIf="isPublishedParty == true" matColumnDef="PublishedParty">
    <th mat-header-cell *matHeaderCellDef mat-sort-header style="min-width: 100px !important;" [ngStyle]="{'color': 'black'}" style="text-align: center;">
      <b>
        Planlanan Miktar
      </b>
    </th>
    <td mat-cell *matCellDef="let row; let i = index" style="min-width: 100px !important;" style="text-align: center;">
      <div>
        Miktar: {{row.PublishedPartyQuantity | number}}
      </div>
      <div>
        Parti: {{row.PublishedPartyCount | number}}
      </div>
    </td>
</ng-container>

TS: TS:

isPublishedParty = false;
private _materialPlan: IMaterialPlan = {};
@Input() 
set MaterialPlan(prm: IMaterialPlan){
  this._materialPlan = prm;
}

get MaterialPlan(): IMaterialPlan {
  return this._materialPlan;
}
displayedColumns: string[] = [
  'StockIntegrationCode',
  'ReceiptName',
  'PublishedParty',
];

dataSource: MatTableDataSource<IMaterialPlanReceiptResult>;
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
@ViewChild(MatSort, { static: true }) sort: MatSort;


constructor(
) {
  if(this._materialPlan.IncludePlannedParty == true){
    this.isPublishedParty == true;
  }
}

For angular to render the table correctly isPublishedParty should be initialized as true.为了让 angular 正确呈现表格, isPublishedParty应初始化为 true。 Otherwise *ngIf removes it from the template and you would get such an error.否则 *ngIf 会从模板中删除它,你会得到这样的错误。 You could set isPublishedParty to false at later time, perhaps in ngAfterViewInit() cycle.您可以稍后将isPublishedParty设置为 false,也许在ngAfterViewInit()循环中。

I think, the problem is, that you hide the ng-container when the condition in your constructor is false for "this._materialPlan.IncludePlannedParty".我认为,问题在于,当构造函数中的条件对于“this._materialPlan.IncludePlannedParty”为假时,您隐藏了 ng-container。

So the solution could be, to remove the column name from the displayColumns array:所以解决方案可能是从 displayColumns 数组中删除列名:

private _materialPlan: IMaterialPlan = {};
@Input()
set MaterialPlan(prm: IMaterialPlan){
    this._materialPlan = prm;
}

get MaterialPlan(): IMaterialPlan {
    return this._materialPlan;
}
displayedColumns: string[] = [];

dataSource: MatTableDataSource<IMaterialPlanReceiptResult>;
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
@ViewChild(MatSort, { static: true }) sort: MatSort;


constructor(
) {
    this.displayedColumns = [
        'StockIntegrationCode',
        'ReceiptName',
    ];
    if(this._materialPlan.IncludePlannedParty == true){
        this.isPublishedParty == true;
        this.displayedColumns.push('PublishedParty');
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误TS2304:在Angular 5中找不到名称&#39;trim&#39; - error TS2304: Cannot find name 'trim' in Angular 5 错误 TS2304:找不到名称“HeatmapOverlay”+ 角度 10 - error TS2304: Cannot find name 'HeatmapOverlay' + angular 10 角度TS错误TS1109 - Angular TS Error TS1109 角材料找不到列 - angular material Could not find column body-parser.d.ts中的打字稿编译错误:找不到符号“缓冲区” - typescript compile error in body-parser.d.ts: Could not find symbol 'Buffer' 在 Angular 7 中实现 redux 会出现错误 TS2307:找不到模块“redux”。 错误 - Implementing redux in Angular 7 gives error TS2307: Cannot find module 'redux'. error 在Centos 6.3上运行“ rails s”时,出现“找不到JavaScript运行时”。 错误 - When running 'rails s' on Centos 6.3 I get a 'Could not find a JavaScript runtime.' error src / polyfills.ts(73,1)中的ERROR时出现web-pack错误:错误TS2304:找不到名称“ global”。 [ng] src / polyfills.ts(73,17): - web-pack error when ERROR in src/polyfills.ts(73,1): error TS2304: Cannot find name 'global'. [ng] src/polyfills.ts(73,17): 错误1找不到符号“ $” - Error 1 Could not find symbol '$' 错误:在 Angular2、Karma、Webpack 和伊斯坦布尔找不到源地图 - Error: Could not find source map for in Angular2, Karma, Webpack and Istanbul
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM