Ich versuche, booleschen Wert in FormControl programmgesteuert festzulegen. Aber das markiert die Form als schmutzig. Going durch Angular docs "programmatischen Änderungen an Wert einer Kontrolle wird es schmutzig nicht markieren" https://angular.io/api/forms/AbstractControl#pristineEinstellung von FormControl in Angular 2 mit booleschem Wert 'true' programmgesteuert ist Formular als schmutzig markiert
Code:
this.formGroup.get(ruleOutput.attributeKey).setValue(JSONUtils.parseJSON(ruleOutput.attributeValue))
FÜR FYI, JSONParser-Code (Denkt nicht, einen Fehler hier):
public static parseJSON(input : any) : any{
try{
return JSON.parse(input);
}catch(Error){
console.log("Inside JSON Utils: Error while parsing input JSON :");
console.log(input);
console.log(Error.toString());
console.log("Return Empty JSON");
return JSON.parse("{}");
}
}
Punkt ist nach dem Festlegen des Werts, Formular wird als schmutzig markiert.
Bitte helfen Sie mir bei der Ursache zu bekommen.
if (ruleDataList && ruleDataList.length> 0) { ruleDataList [0] .ruleOutputList.forEach ( ruleOutput => { if (DisplayUtils.isKeyDisplayable (ruleOutput.attributeKey, "*")) { this.formGroup .get (ruleOutput.attributeKey) .setValue (JSONUtils.parseJSON (ruleOutput.attributeValue)); this.formGroup.get (ruleOutput.attributeKey) .markAsPristine; } } ) this.ruleDataAlreadyExists = true; } –
Bitte erstellen Sie eine Demo dafür, ich sehe nicht, warum dies passieren sollte. – Alex