使用对象变量设置下拉菜单

时间:2019-01-30 11:53:21

标签: typescript data-binding drop-down-menu angular7

我想将下拉菜单设置为在加载组件时加载的对象(currentSelectedModel)。

该组件具有一个带有属性(名字和姓氏)的对象。从导航参数接收到此对象。将currentSelectedModel设置为给定的对象。

html代码

<label for="person">person</label>
    <select id="person" [(ngModel)]="offer.person" >
    <option *ngFor="let person of personList"
              [ngValue]="person">{{person.firstName}} {{person.lastName}}</option>
    </select>

打字稿

currentSelectedModel = new model();
modellist = model[] = []

    ngOnInit() {
            this.modellist = this.getlistFromDataSource();
            this.route.params.subscribe(params => {
                if (params['id'] !== undefined) {
                    this.objectService.get(params['id']).subscribe(object => {
                        this.currentSelectedModel = object;
                    });
                }
            });
        }

下拉菜单显示加载对象的名字和姓氏。

0 个答案:

没有答案