Closed stryju closed 9 years ago
I'm not certain that I completely understand why you want this. The name
attribute simply adds the NgModelController
for that instance to the scope. Which you then pass to ng-messages
. So, in an ng-repeat
scenario, you have to make the name
dynamic with interpolation so you don't get property overwrites--as you indicated (only works +1.3 by the way).
Personally, I think the way that it works currently is simple and adding some magic to accomplish what you're suggesting to angular's core would add unnecessary complexity. However, if you really want it, you could write a directive that would give you what you want. Something like array-name
or something, which would require the ngModel controller, then push the controller to the property (array) passed. Shouldn't be too complicated. I think that'd probably be a better way to go about it.
i'm not suggesting to make it like that, just wanted to know the reasoning behind that.
AFAIK form elements with [name="someParam[]"]
indicates that the given parameter is an array and should be interpreted as one (at least during my past adventure with PHP)
Yeah, that's not the way it works in angular: https://docs.angularjs.org/api/ng/directive/input#usage
name (optional) string - Property name of the form under which the control is published.
fair enough :)
are there any plans for better support of "array-like" form params?
now, none of those work:
[name=“values[]”]
+[ng-messages="values[]"
[name=“values[]”]
+[ng-messages="values[{{$index}}]"]
[name=“values[{{$index}}"]
+[ng-messages="values[{{$index}}]"]
the only working "hacky" solution would be something like
[name=“values_{{$index}}”]
+[ng-messages="values_{{$index}}"]
, but that strips the array-like url params functionality