ComboBoxComponent提供了切换comboBox弹出窗口可见性的方法。我想显示已经打开的comboBox。我有以下实施:
datalist.component.html
<kendo-combobox #attributecombobox></kendo-combobox>datalist.component.cs
@Component({
templateUrl: './datalist.component.html'
})
export class DatalistComponent implements OnInit {
@ViewChild('attributecombobox') public attributeCombobox: ComboBoxComponent;
}我尝试过设置构造函数:
constructor() {
this.attributeCombobox.toggle(true);
}不起作用。我还尝试了OnInit生命周期挂钩:
ngOnInit() {
this.attributeCombobox.toggle(true);
}它也不起作用。
什么是正确的方法?提前谢谢。
更新1
抱歉,我没有透露所有密码。ComboBox实际上有一个*ngIf
datalist.component.html
<kendo-combobox #attributecombobox *ngIf="setAttribute"></kendo-combobox>datalist.component.cs
@Component({
templateUrl: './datalist.component.html'
})
export class DatalistComponent implements OnInit {
@ViewChild('attributecombobox') public attributeCombobox: ComboBoxComponent;
setAttribute = true;
ngOnInit() {
this.attributeCombobox.toggle(true);
}
}因此,我想我发现了kendo-combobox元素使用*ngIf的问题,正如您在这个柱塞中看到的那样,我从George柱塞中分叉(谢谢乔治)。
更新2
我提交了一个被归类为bug 这里的问题。
发布于 2017-04-03 14:37:42
打开组件的最早位置是在ngOnInit (您的第二次尝试)中。调用切换方法对我来说很好:
ngOnInit() {
this.combo.toggle();
}下面是一个可运行的柱塞:
http://plnkr.co/edit/ssbftD6hg3f7LM86CIPD?p=preview
更新
实际上,如果应用了像ngOnInit这样的结构指令,那么组件将无法在ngIf钩子中使用。基本上,这会使
<ng-template [ngIf]="show">....combobox here... </ng-template>正如您可能已经注意到的,模板中的组件将不在第一个init中。解决方案是使用稍后将在组件初始化中调用的钩子,如AfterViewInit:
ngAfterViewInit() {
setTimeout(() => {
this.combo.toggle();
});
}更新后的柱塞演示可以在这里找到- http://plnkr.co/edit/quLb3oeiVRJfqACqGKEK?p=preview。
https://stackoverflow.com/questions/43181695
复制相似问题