Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.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
Javascript 使用ViewChild()获取角度视图中的元素_Javascript_Node.js_Angular_Typescript - Fatal编程技术网

Javascript 使用ViewChild()获取角度视图中的元素

Javascript 使用ViewChild()获取角度视图中的元素,javascript,node.js,angular,typescript,Javascript,Node.js,Angular,Typescript,我想得到一个模态中的table元素 我将提供下面的模式html代码,以及我如何尝试访问数据表。 数据表是priming <ng-template #industryModal> <div class="modal-body"> <h4>{{'Instance.IndustryModal.Header' | translate }}</h4> <p class="m-t-20">{{'Instance.IndustryMod

我想得到一个模态中的table元素 我将提供下面的模式html代码,以及我如何尝试访问数据表。 数据表是priming


  <ng-template #industryModal>
<div class="modal-body">
  <h4>{{'Instance.IndustryModal.Header' | translate }}</h4>
  <p class="m-t-20">{{'Instance.IndustryModal.Branch' | translate }}: {{instanceObj['personaldata.Branch']}}</p>
  <p-table #dt [value]="industries" [paginator]=true [rows]="10" paginatorPosition="bottom" 
    [sortField]="sortField" [sortOrder]="sortOrder" styleClass="industry-data" [first]="first">

    <ng-template pTemplate="caption">
      <i class="fa fa-search" style="margin:4px 4px 0 0"></i>
      <input type="text" pInputText size="50" placeholder="{{'Common.Search' | translate}}"
        (keyup)="dt.filterGlobal($event.target.value)" style="width:auto">
    </ng-template>
    <ng-template pTemplate="body" let-industry>
      <tr>
          <td>
            <div class="industry-list-item" (click)="selectIndustry(industry)"
            [ngClass]="{'select': (selectedIndustry && industry.Name == selectedIndustry.Name)}">
            <div class="vin-number">{{industry.Id}}</div>
            <div class="industry-brand">{{industry.Name}}</div>
            <div class="industry-warning warning-{{industry.Warning}}">
              <i class="fa fa-exclamation-triangle warning-message" *ngIf="industry.Message != null"
                pTooltip="{{industry.Message}}" tooltipPosition="top" tooltipZIndex="1100"></i>
              <span class="">{{industry.Warning}}</span>
              <i class="fa fa-check selected-icon"
                *ngIf="(selectedIndustry && industry.Name == selectedIndustry.Name)"></i>
            </div>
          </div>
          </td>
      </tr>
  </ng-template>
  </p-table>
  <div class="clearfix">&nbsp;</div>
  <div class="float-right">
    <button type="button" class="btn secondary-btn m-r-16"
      (click)="closeIndustryModal()">{{'Instance.Cancel' | translate}}</button>
    <button type="button" class="btn btn-primary primary-btn"
      (click)="saveIndustry()">{{'Instance.Save' | translate}}</button>
  </div>
</div>
</ng-template>

但当我控制台DataVew时,它显示未定义。

当使用ViewChild时,您需要使用
#dt
添加类似这样的模板引用变量


当使用ViewChild时,您需要使用
#dt


请同时包括p表的起始标签。请同时包括p表的起始标签
   @ViewChild('dt') dataveiw: BsModalRef;
<ng-template #dt pTemplate="caption"></ng-template>
@ViewChild('dt') dataveiw: BsModalRef;