English 中文(简体)
2 装在电离层中不使用的方法数据 6
原标题:2 Way data binding not working in ng-select Angular 6

我在申请中使用了弱智。

我的构成部分班子

export class ExampleComponent {
     selectedCoursesList: Course[] = [];
     courseList: any[] = [];

     removeCourse( course: Course) {
         this.selectedCoursesList.forEach((item, index) => { 
          if (item === course) { 
                this.selectedCoursesList.splice(index, 1);          
          }
        });
    }
 }

and my html is

     <ng-select  placeholder="Choose course" [multiple]="true" 
        (ngModelChange)="updatecourse($event);" 
        [(ngModel)]="selectedCoursesList">
        <ng-option *ngFor="let course of courseList" [value]="course" >
                    {‌{course.name}} 
        </ng-option>
     </ng-select>

在此,我要谈两点。

  1. Un-selecting particular selected values of ng-select
  2. 2 way Data binding

谁能告诉我我我我什么是错的?

感谢

问题回答

我通过在我的“历史”中加上“历史”来实现这一目标。

     <ng-select  [formControl]="courses" placeholder="Choose course" [multiple]="true" 
         [(ngModel)]="selectedCoursesList">
            <ng-option *ngFor="let course of courseList" [value]="course" >
                {‌{course.name}} 
            </ng-option>
      </ng-select>

页: 1 课程方法 增 编

(c) 选择WinaryList;

 export class ExampleComponent {
    selectedCoursesList: Course[] = [];
    courseList: any[] = [];
    courses= new FormControl();
    removeCourse( course: Course) {
         this.selectedCoursesList.forEach((item, index) => { 
             if (item === course) { 
                 this.selectedCoursesList.splice(index, 1);          
             }
         });
         (c) 选择WinaryList;
     }
 }

当我从阵列中删除课程时,它自动从选定的名单中删除该课程。

首先,你们应该像现在这样使用弱智。

<ng-select class="custom" placeholder="Select type of Faq Post"
   [(ngModel)]="selectedType"
   [items]="mapedData"
   bindLabel="value"
   bindValue="key"
   (change)="dataModelChanged()">
 </ng-select>

ng子和ng子将自动约束价值,因此,你无需使用ng。 另外,电梯也有改变方法,即产出活动排放物。

 dataModelChanged() {
    console.log(this.selectedType);
  }

如今,每改变纳克子的数值,你将具有将储存在选定地点中的ng升值。 类型

Use (change) event from html like below

  <ng-select [items] = "arrobjCategories"  bindLabel = "name"
bindValue = "id" [(ngModel)] = "selectedProductCategoryId"
(change) = "onProductCategoryChange($event)"> </ng-select>
Use the change event in type script file like below

  public onProductCategoryChange(event){
    console.log(event);
  }

该活动将包括实际选定的数据。





相关问题
Angular matSort not working on Date column by desc

Trying to sort the material table with date column , date format is MM/DD/YYYY ,h:mm A , order of date is not by latest date and time. Anything which i missed from the below stackblitz code. https:/...

热门标签