无法使用设置md-select默认文本(值已设置,但文本不是)

时间:2017-04-01 18:09:32

标签: javascript angularjs angular-material

这一定是一件非常容易的事情,但我无法理解。

当我使用<select>时,即使我使用<md-select>,我的代码就像魅力一样,但<md-select>仅适用于静态选项。

组件:

this.clientService.getClients()
    .subscribe(
        items => {
            this.clients = items;
    });

此代码有效:

<select [(ngModel)]="item.client" name="item.client">
    <option *ngFor="let client of clients" value="{{client.$key}}">
        {{client.name}}
    </option>
</select>

此代码不起作用:

<md-select [(ngModel)]="item.client" name="item.client">
    <md-option *ngFor="let client of clients" value="{{client.$key}}">
        {{client.name}}
    </md-option>
</md-select>

此代码可以工作:

<md-select [(ngModel)]="item.phase" name="item.phase">
    <md-option value="Phase1">Phase 1</md-option>
    <md-option value="Phase2">Phase 2</md-option>
    <md-option value="Phase3">Phase 3</md-option>
</md-select>

我错过了什么或者它是材料代码库中的错误吗?

@ angular / cli:1.0.0 节点:7.4.0 os:darwin x64

"dependencies": {
  "@angular/common": "^2.3.1",
  "@angular/compiler": "^2.3.1",
  "@angular/core": "^2.3.1",
  "@angular/forms": "^2.3.1",
  "@angular/http": "^2.3.1",
  "@angular/material": "^2.0.0-beta.1",
  "@angular/platform-browser": "^2.3.1",
  "@angular/platform-browser-dynamic": "^2.3.1",
  "@angular/router": "^3.3.1",
  "angularfire2": "^2.0.0-beta.7",
  "core-js": "^2.4.1",
  "firebase": "^3.6.7",
  "rxjs": "^5.0.1",
  "ts-helpers": "^1.1.1",
  "zone.js": "^0.7.2"
},
"devDependencies": {
  "@angular/compiler-cli": "^2.3.1",
  "@types/jasmine": "2.5.38",
  "@types/node": "^6.0.42",
  "angular-cli": "1.0.0-beta.26",
  "codelyzer": "~2.0.0-beta.1",
  "extract-text-webpack-plugin": "^2.0.0-rc.0",
  "jasmine-core": "2.5.2",
  "jasmine-spec-reporter": "2.5.0",
  "karma": "1.2.0",
  "karma-chrome-launcher": "^2.0.0",
  "karma-cli": "^1.0.1",
  "karma-jasmine": "^1.0.2",
  "karma-remap-istanbul": "^0.2.1",
  "protractor": "~4.0.13",
  "ts-node": "1.2.1",
  "tslint": "^4.3.0",
  "typescript": "~2.0.3"
}

0 个答案:

没有答案