使用模型中的数组在 angular 2+ 中提交表单

Submit form in angular 2+ with arrays in model

如何使用数组创建模型

我的回复:

 {
    "mail": "test@tes.com",
    "password": "test",
    "field_user_terms_and_conditions": {
        "und": {
            "value": "1"
        }
    },
    "profile_main":{
        "field_your_name":{
            "und":{
                "0":{
                    "value":"test"
                }
            }
        },
        "field_type_of_diet":{
            "und":{
                "value":"vegan"
            }
        }
    }
}

然后我需要创建一个模型来发送提交表单

我的模特:

export class UsuarioModel {

    mail: string;
    password: string;
    -- this is my problem field_user_terms_and_conditions: string;

}

我的HTML

<input type="checkbox" name="terms" class="form-checkbox check-style"
                                        [(ngModel)]="usuario.field_user_terms_and_conditions">

最后 return 一个响应错误...如果我将我的响应放在 Postman 中,工作正常..

知道我该怎么做吗?

https://stackblitz.com/edit/angular-wnew3y

中的示例

谢谢sssss

抱歉,我不明白该怎么做...我已经在我的模型中声明了我的价值,然后在我的服务中创建了我的数据,所以 POST 它。

我的服务示例:

    const authData = {
      returnSecureToken: true,
            profile_main: {
                field_type_of_diet:{
                  und: {
                    value: usuario.type_of_diet
                  }
                }
            }, .........

    };

感谢大家的耐心等待,如果我可以帮助这里的任何用户post请告诉我:)