getElementById возвращает значение null при его применении для выбора Option - PullRequest
0 голосов
/ 08 мая 2020

В моем angular приложении я пытаюсь выполнить некоторый условный код, когда результат истинный Я хочу отключить параметр выбора, содержащий список объектов c Dynami, когда пытаюсь получить идентификатор этого, выберите его return null !!

ngOnInit() {
    this.setScripts()
    this.http.get('api/cities').subscribe((cities: any[]) => {
      this.cities = cities;
    })

    this.http.get('api/user').subscribe(user => {
      this.currentUser = user
      localStorage.removeItem('currentUser')
      localStorage.setItem('currentUser', JSON.stringify(this.currentUser))

      this.user.patchValue({
        firstName: this.currentUser.firstName,
        lastName: this.currentUser.lastName,
        email: this.currentUser.email,
        profession: this.currentUser.profession,
        gender: this.currentUser.gender,
        birthDate: this.currentUser.birthDate,
        phone: this.currentUser.phone,
        oldPassword: this.currentUser.oldPassword,
        password: this.currentUser.newPassword,
        address: this.currentUser.address,
        postalCode: this.currentUser.postalCode,
        city: this.currentUser.city._id
      })
    })
    this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
    if (this.compareDatesByDays(new Date().toISOString(), JSON.parse(localStorage.currentUser).municipalityDateChange) < 10) {
      this.hideSelectMunicipality()
    }
  }



  hideSelectMunicipality(){
    $('#selectCity').prop('disabled', true);
   }

***html

  <div class="col-lg-7">
                  <select id="selectCity" name="city" class="custom-select form-control rounded" formControlName="city">
                    <option *ngFor="let city of cities" [value]="city._id" >{{city.name}}</option>
                  </select>
                </div>

Ответы [ 3 ]

1 голос
/ 08 мая 2020

Используйте это,

hideSelectMunicipality(){
this.user.controls.city.disable();
}
0 голосов
/ 08 мая 2020

Я думаю, что ваш текущий пользователь муниципалитетДатаИзменения дней меньше 10, поэтому функция "hideSelectMunicipality" выполнена, пожалуйста, проверьте данные пользователя в базе данных.

0 голосов
/ 08 мая 2020

Я бы предложил использовать для этой цели ngClass и отключить их при некоторых условиях

...