如何在json文件中将json文件中的数据绑定到mat-select

时间:2019-03-12 10:35:04

标签: angularjs typescript

这是打字稿,我将城市绑定到垫子选择上

    import { Component } from '@angular/core';
    import { FormControl, Validators } from '@angular/forms';
    import { ActivatedRoute } from '@angular/router';
    import { MatProgressButtonOptions } from 'mat-progress-buttons';
    import { of } from 'rxjs';
    import 'rxjs/add/operator/map';
    import { delay } from 'rxjs/operators';

这是json文件

  

从'../json/citymunc.json'中将*导入为城市;

 import { ApiUserService } from '../service/api.user.service';

    export interface Religion {
        value: string;
        viewValue: string;
      } 

    @Component({
        selector: 'register',
        templateUrl: '../view/register.component.html'
      }) 
      export class RegisterComponent {


**This is the one I will bind to html**
    listed:any[] = [
        {
             value: City.RECORDS.forEach(element => {
                // City.RECORDS.map(res => res.citymunCode);  
                element.citymunCode;
             }), 
             viewValue: City.RECORDS.forEach(element => {
                element.citymunDesc;  
             })
        }
    ];

    Religions: Religion[] = [
        {value: 'B', viewValue: 'Buddhism'},
        {value: 'C', viewValue: 'Christian'},
        {value: 'I', viewValue: 'Islam'},
        {value: 'RC', viewValue: 'Roman Catholic'},
        {value: 'O', viewValue: 'Other'},
      ];

    email = new FormControl('', [Validators.required, Validators.email]);
    getEmailValidation() {
      return this.email.hasError('required') ? 'You must enter a value' :
          this.email.hasError('email') ? 'Not a valid email' :
              '';
    }

这是HTML代码

   <mat-form-field>
      <mat-select placeholder="City" [(ngModel)]="user.City" id="City" name="City" required>
      <mat-option *ngFor="let city of listed" [value]="city.value" ngDefaultControl>{{city.viewValue}}</mat-option>
      </mat-select>
     </mat-form-field>

请帮助我解决这一问题。 谢谢您的高级.................................................... ...........

0 个答案:

没有答案