Angular 4 setting selected option in Dropdown

前端 未结 6 1049
渐次进展
渐次进展 2020-12-13 17:34

several questions about this and diffrent answeres. But none of them realy answeres the question. So again:

Setting default of a Dropdown select by value isnt workin

6条回答
  •  臣服心动
    2020-12-13 18:06

    Here is my example:

    And in component you must get values from select:

    contactMethods = [
        { id: 1, label: "Email" },
        { id: 2, label: "Phone" }
    ]
    

    So, if you want select to have a default value selected (and proabbly you want that):

    contact = {
        firstName: "CFR",
        comment: "No comment",
        subscribe: true,
        contactMethod: 2 // this id you'll send and get from backend
    }
    

提交回复
热议问题