Gnanasuriyan Gnanasuriyan - 1 year ago 80
JSON Question

Angular data binding - binding with JavaScript object should be case insensitive

I am having some weird scenario. I am receiving JSON object from server and the keys are not unique always. For example,

Sometime I am getting response like

{ firstName: 'Gananasuriyan', lastName: 'A'} and some times it will be

{FirstName: 'Gnanasuriyan', LastName: 'A'}.

I can not change server side API but I need to bind that JSON in view.

I am looking some best solution. I am ready to change angular source code as well.

Answer Source

You can set the value for the model

model.firstName = model.firstName || model.FirstName; 
// If model.firstName is undefiend, get model.FirstName

After that, just bind the value to view

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download