Gnanasuriyan Gnanasuriyan - 6 months ago 12
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.


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