Как связать данные в json-файле с mat-select в angularjs машинописи - PullRequest
0 голосов
/ 12 марта 2019

Это машинопись, и я привязываю город к mat-select

    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

import * какГород из '../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>

Пожалуйста, помогите мне решить эту проблему.Заранее благодарю.........................................................

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...