简体   繁体   English

Angular 9、如何通过ngFor在ng-select中聚焦特定字段

[英]Angular 9, how to focus specific field in ng-select through ngFor

Im pretty new with angular & js.我对 angular & js 很陌生。 I have 3 ng-select through my ngFor loop.我通过我的 ngFor 循环有 3 ng-select。

<div class="filter-input" *ngFor="let input of data; let i = index">
                    <div class="subtitle">{{ input.title | translate }}</div>
                    <ng-select
                    class="ng-select"
                    bindLabel="{{ input.bindLabel }}"
                    bindValue="{{ input.bindLabel }}"
                    [items]="input.data"
                    [multiple]="input.multiple"
                    [clearable]="input.clearable"
                    [searchable] = "input.searchable"
                    groupBy="{{ input.groupBy }}"
                    [selectableGroup]="input.selectableGroup"
                    [selectableGroupAsModel]= "input.selectableGroupAsModel"
                    [addTag]="input.addTag"
                    (change)="isStepSelected($event, i)"
                    [(ngModel)]="input.selection">

                    </ng-select>

That i want to do is to enabled the submit button only if some items from the first dropdown are selected and matching with the items from the 2nd dropdown. That i want to do is to enabled the submit button only if some items from the first dropdown are selected and matching with the items from the 2nd dropdown. Using a method like使用类似的方法

public isStepSelected(event, id) {

        if (id === 0 && event) {
            event.length > 0 ? this.isDisabled = false : this.isDisabled = true;
        }

        if(id ===1 && event){
           //do something
        }

I don't know how to perform this, or if exist a better way to do it.我不知道如何执行此操作,或者是否存在更好的方法来执行此操作。 Thx for help: :)谢谢帮助::)

In your code I have added在您的代码中,我添加了

[disabled]="i > selectedValue" [禁用]="i > selectedValue"

in html code.在 html 代码中。

<div class="filter-input" *ngFor="let input of data; let i = index">
                    <div class="subtitle">{{ input.title | translate }}</div>
                    <ng-select
                    class="ng-select"
                    bindLabel="{{ input.bindLabel }}"
                    bindValue="{{ input.bindLabel }}"
                    [items]="input.data"
                    [multiple]="input.multiple"
                    [clearable]="input.clearable"
                    [searchable] = "input.searchable"
                    groupBy="{{ input.groupBy }}"
                    [selectableGroup]="input.selectableGroup"
                    [selectableGroupAsModel]= "input.selectableGroupAsModel"
                    [addTag]="input.addTag"
                     [disabled] = "i > selectedValue"
                    (change)="isStepSelected(i)"
                    [(ngModel)]="input.selection">

                    </ng-select>
</div>

and added a variable and increased value.并添加了变量和增加的值。 while changing.在改变的同时。

selectedValue = 0;

public isStepSelected(value) {
 value++;
 this.selectedValue = value; 
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM