很抱歉有很多关于这个错误的问题,但我的很奇怪。该功能起作用了,几分钟后它不再起作用了。没有“订阅”这一行,LocalStorage 运行良好。谢谢你的帮助,我在这个错误上花了很多时间..:'(
import { Component, OnInit } from '@angular/core';
import { StatutService } from '../statut.service';
import { Statut } from '../statut';
import { FormControl, FormGroup } from '@angular/forms';
import { Router } from '@angular/router';
@Component({
selector: 'app-accueil-admin',
templateUrl: './accueil-admin.component.html',
styleUrls: ['./accueil-admin.component.scss']
})
export class AccueilAdminComponent implements OnInit {
statutForm!: FormGroup;
//isSubmitted = false;
constructor(private statutService: StatutService) { }
ngOnInit(): void {
this.statutForm = new FormGroup({
poste : new FormControl(''),
etat : new FormControl(''),
client : new FormControl(''),
});
}
recherche() {
//this.isSubmitted = true;
console.log('Statut saisi', this.statutForm.value);
let poste = this.statutForm.value.poste;
let etat = this.statutForm.value.etat;
let client = this.statutForm.value.client;
this.statutForm.value.poste.subscribe((data: Object) => {
// Tableau des clés et des valeurs de l'objet
let keys = Object.keys(data);
let values = Object.values(data);
for (let i = 0; i < keys.length; i++) {
if (keys[i] == 'poste') { poste = values[i]; }
if (keys[i] == 'etat') { etat = values[i]; }
if (keys[i] == 'client') { client = values[i]; }
}
let leStatut = new Statut (poste, etat, client);
this.statutService.addStatut(leStatut);
[enter image description here][1]});
}
答案 0 :(得分:0)
this.statutForm.value.poste
不是可观察的,它是字段的普通值。如果你想在变化之后观察到,你可以使用
this.statutForm.get('poste').valueChanges.subscribe(/* ... */)
或
this.statutForm.controls.poste.valueChanges.subscribe(/* ... */)