typescript 访问错误:6142访问错误:NG0300:多个元件与标记名为th的节点匹配

eeq64g8w  于 2023-03-09  发布在  TypeScript
关注(0)|答案(2)|浏览(139)

我在Angular中创建类似主详细信息页面的内容,我有工作单,每个工作单都有任务(应用服务),因此在工作单编辑页面中,我尝试将应用服务列为子组件,以下是我的AppliedServices. ts代码:

import { Component, Input, OnInit } from '@angular/core';
import { AppliedServiceDto, AppliedServiceService } from '@proxy/applied-services';
import { WorkorderService } from '@proxy/workorders';

@Component({
  selector: 'app-applied-services',
  templateUrl: './applied-services.component.html',
  styleUrls: ['./applied-services.component.scss']
})
export class AppliedServicesComponent implements OnInit {
  @Input() id: string
  appliedServices:AppliedServiceDto[];
  columns:string[]=["completedTask","employeeName","actions"];
  constructor(private workorderService:WorkorderService) { }

  ngOnInit(): void {
this.workorderService.getFullWorkorderDetailsByWorkorderid(this.id).subscribe((work)=>{this.appliedServices=work.appliedServices});
console.log(this.appliedServices);
    console.log("im child"+this.id);
  }

}

这是html:

<mat-card>
    <mat-card-header class="w-100">
      <mat-card-title-group class="w-100">
        <mat-card-title class="abp-card-title"
          >Applied services
          </mat-card-title
        >
        <button
    id="create"
    mat-raised-button
    color="primary"
    type="button"
 
  >
    <i class="fa fa-plus mr-1"></i>
    <span>New Applied service</span>
  
        </button>
      </mat-card-title-group>
    </mat-card-header>
    <mat-card-content>
  
        <table
        mat-table
        [dataSource]="appliedServices"
        class="w-100"
      
      >
        <tr mat-header-row *matHeaderRowDef="columns"></tr>
        <tr mat-row *matRowDef="let myRowData; columns: columns"></tr>
    
        <ng-container matColumnDef="completedTask">
          <th mat-header-cell *matHeaderCellDef mat-sort-header>
            {{'::Completed Task' | abpLocalization}}
          </th>
          <td mat-cell *matCellDef="let element">{{element.completedTask}}</td>
        </ng-container>
    
        <ng-container matColumnDef="employeeName">
          <th mat-header-cell *matHeaderCellDef mat-sort-header>
            {{'::Customer' | abpLocalization}}</th>
            <td mat-cell *matCellDef="let element"
            prop="element.employeeName"
            >
           {{element.employeeName}}
            </td>
          </ng-container>
        <ng-container matColumnDef="actions">
          <th mat-header-cell *matHeaderCellDef> {{'::Actions' | abpLocalization}} </th>
          <td mat-cell *matCellDef="let element">
            <button mat-raised-button color="primary" [matMenuTriggerFor]="menu" [matMenuTriggerData]="{id: element.id}">
              <mat-icon>settings</mat-icon>
              {{'::Actions' | abpLocalization}}
              <mat-icon>expand_more</mat-icon>
            </button>
          </td>
      </ng-container>
    
      </table>
     
    </mat-card-content>
  </mat-card>
  
  <mat-menu #menu="matMenu">
    <ng-template matMenuContent let-id="id">
      <button mat-menu-item >
        {{ '::Edit' | abpLocalization }}
      </button>
      <button mat-menu-item >
        {{ '::Delete' | abpLocalization }}
      </button>
    </ng-template>
  </mat-menu>

该表是不显示和我有这个错误在这控制台:访问错误:6142访问错误:NG0300:多个元件与标记名th的节点匹配。
我试图删除标题,它的工作正常,我该怎么做,使它的工作与标题提前感谢

z9gpfhce

z9gpfhce1#

您需要确保使用viewchild将Sort模块分配给mat-table。
例如:tsx:

@ViewChild('empTbSort') empTbSort = new MatSort();

 async ngOnInit() {
this.availableDataDataSource.sort = this.empTbSort;
 }

网页:

<mat-table class="mat-elevation-z8" mat-table [dataSource]="availableDataDataSource"  (matSortChange)="sortData($event)" matSort #empTbSort="matSort" >

Source

gjmwrych

gjmwrych2#

通过从标签中删除mat-sort-header解决

相关问题