yasuto2002 / todo-app-angular

0 stars 0 forks source link

型付きのフォームグループを使用する #5

Open yasuto2002 opened 1 year ago

yasuto2002 commented 1 year ago

強引に実装してみた

todoFb = new FormGroup<TodoRequestForm>({

title: new FormControl('', [Validators.required,Validators.pattern("^[0-9a-zA-Zぁ-んーァ-ンヴー一-龠]*$")]),

body: new FormControl('',[Validators.required,Validators.pattern("^[0-9a-zA-Zぁ-んーァ-ンヴー一-龠\s]*$")]),

state_code: new FormControl(0,Validators.required),

category_id: new FormControl(0,Validators.required),

});
onSubmit():void{

const todoRequest: TodoRequestForm = this.todoFb.controls as TodoRequestForm;

this.todoService.addTodo(todoRequest).subscribe(_ => this.router.navigate(["todo"]));

}

エラー

Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'title' -> object with constructor 'FormControl'
    |     property '_parent' -> object with constructor 'FormGroup'
    --- property 'controls' closes the circle undefined