Materializecss选择多个angular2 formControlName

时间:2017-02-07 23:59:09

标签: angular multi-select materialize

如何使用formControlName选择materializecss和Angular2的默认值(我的意思是来自数据库的值)?我有一个观察列表,每个参与者列表,我想选择用户列表中的所有与会者。

<select class="icons" [materializeSelectOptions]="users" materialize="material_select" formControlName="attendees" multiple >
     <option *ngFor="let user of users" [value]="user" class="right circle">{{user.name}}</option>
</select>

修改

为了吸引与会者:

 this._route.params.switchMap((params: Params) =>
      this._observationService
          .getObservation(params['key']))
          .subscribe((data) => {
               data.attendees.forEach((userSelected) => {
                    this.selectedUser.push({
                         id: userSelected.attendees,
                         name: userSelected.name
                    });
               });
       this.observationForm.patchValue(data);
 });

获取所有用户:

this._userService.getList()
    .subscribe(users => {
        users.forEach((user) => {
           this.users.push({ email: user.email, name: user.name });
        });
     });

这是用户对象:

{
    createdAt: 1486419737973,
    email:"gage@ge.fr",
    lastConnection: 1486419737973,
    name: "Gage",
    role: "membre",
    updatedAt: 1486419737973     
}

这是观察对象的与会者:

{
    ...
    attendees:[
       0: {
         email: "bla@bla.fr"
         name: "Bla" 
       },
    ],
    ...

}

如果我改变:

<option *ngFor="let user of users" [value]="user" class="right circle">{{user.name}}</option>

用这个:

<option *ngFor="let user of selectedUser" [value]="user" class="right circle">{{user.name}}</option>

仅显示和选择与会者用户。

0 个答案:

没有答案