1
I need to create a model name dynamically, but when creating obj the angular does not accept that I try to create the obj name dynamically. Has anyone ever done this or knows how to proceed?
The problem is occurring in the data-ng-model, wanted to create an object with the name form with all its attributes dynamically.
Below is the HTML example
<div data-ng-repeat="campos in lista">
<div data-ng-switch="campo.type">
<div data-ng-switch-when="text">
<label data-ng-if="campo.label">{{campo.label}}</label>
<input type="text" name="{{campo.name}}" placeholder="{{campo.placeholder}}" data-ng-model="form.{{campo.name}}" />
</div>
</div>
</div>
In case it will create a vector and not a correct object?
– Hiago Souza
You are correct and wrong. Simply put, an object, in Javascript, is a vector (a map, if it is methodical) of attributes. That is, structurally, a vector and an object are very similar. So much so that there is no
typeof arr === "array"
and the method should be usedArray.isArray
. This article can help you understand a little more (in English) http://www.quirksmode.org/js/associative.html– Vinícius Gobbo A. de Oliveira
Anyway, I hadn’t thought of it that way. Thank you.
– Hiago Souza
Solve my problem this way.
– Hiago Souza