How to change button label in angularjs according to requirement?

前端 未结 2 1915
轮回少年
轮回少年 2021-01-29 01:28

I want to change the label of same button in angularjs according to requirement, same button can be for update and submit.

See the following demo,

Above demo is

2条回答
  •  醉梦人生
    2021-01-29 02:27

    I understand that while while adding data you wanted to show Submit button label & show Update button label while updating record.

    So as normal practice you are getting this value from the DB, so I'd suggest you to add id column in this object which will be there with fields. Now object will look like {id: 1, field1: '1', field2: 2} so if the element has id that means it has persisted in the database. And obviously if you don't have id in fields record means it has been added from UI.

    So the whole logic will look at the id property of your object, if you have id in the record then it will show Update as button label otherwise it would be Submit

          
    

    So for make your logic working good, you need to get the list again from the database to make your UI consistent.

    Working Plunkr

提交回复
热议问题