'Angular getRawValue but only valid value [closed]

Hi I need get all value (disabled field too), so I use getRawValue() but I don`t want invalid field value. What can I do ?



Solution 1:[1]

I would do something like that:

private function _getValuesNotInvalid(): any {
    const rawValues = this.form.getRawValue();
    Object.keys(this.form.controls).forEach(item => {
        if(!this.form.get(item).valid) {
           delete(rawValues[item])
        }
    });

    return rawValues;
}

PS: _getValuesNotInvalid(): >>> any <<< is not recomended, since any is not a great way to achieve things. Said that you can create a custom interface to solve that.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jacopo Sciampi