我有一个带有像这样定义的 ng-template 模态框的 html 文件
HTML
<ng-template #content let-modal>
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">Title</h4>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form [formGroup]="form">
<div class="form-group">
<div class="row">
<div class="col-12">
<label for="select">Select from:</label>
<div class="form-group floating-label">
<ng-select #selectList formControlName="selectList" [items]="dropdownList" multiple="true" bindLabel="name" bindValue="id" placeholder="Select an Item" >
</ng-select>
</div>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" (click)="modal.close('Save click')">Save</button>
</div>
</ng-template>
<ng-container *ngTemplateOutlet="content"></ng-container>
我的 component.ts 有一个ViewChild定义,我尝试根据加载的数据以编程方式选择值。但是,选择似乎什么都不做。我在两个不同的位置执行完全相同的过程,这些位置并非ng-template没有问题。我知道我在这里遗漏了一些东西。
组件.ts
@ViewChild('selectList') selectList;
let item = this.selectList.itemsList.findByLabel(loadedData.name);
this.selectList.select(item); //does nothing
对此的任何帮助表示赞赏。