md-select error on name attribute
I need to define the name on an md-select programatically using {{id}}. However, when doing so an error is thrown...
TypeError: Cannot read property '$name' of undefined
the offending code is on line 8029 of angular-material.js...
if (attr.name && formCtrl) {
var selectEl = element.parent()[0].querySelector('select[name=".' + attr.name + '"]')
formCtrl.$removeControl(angular.element(selectEl).controller());
}
it looks to be a timing issue of when the attr.name is bound, as a hack I put the function into a $timeout and it worked correctly.
I am having the same issue. I am defining the name of an mdSelect directive using the following code:
<md-select name="type{{$index+1}}"
I am getting: TypeError: Cannot read property '$name' of undefined
FYI: This is part of an ng-repeat loop.
Any word on this? For someone that cannot hack angular-material.js, this is a serious issue...
Same issue here (version1.4.0) even when I don't set it programatically, I can just leave it without 'name' for now but then I get no validation.
<md-input-container>
<md-select name="addressCountry" placeholder="Country" ng-model="company.addressCountry" required>
<md-option ng-value="country" ng-repeat="country in countries">{{ country }}</md-option>
</md-select>
<div class="errors" ng-messages="companyForm.addressCountry.$error" ng-show="companyForm.addressCountry.$touched && companyForm.addressCountry.$invalid">
<div ng-message="required">Country required</div>
</div>
</md-input-container>
I don't think there is anything wrong with my code.
Have same problem, +1
it happens here:
if (attr.name && formCtrl) {
var selectEl = element.parent()[0].querySelector('select[name=".' + attr.name + '"]')
formCtrl.$removeControl(angular.element(selectEl).controller()); // <--- controller() returns undefined
}
https://github.com/angular/material/commit/aa440efcb381a61abb49ea846d1fe0b458cc3a50#diff-d7b463f733c2e3fbc783f38073561b74R153
Intention is unclear to me. If I step through the code in debugger, hidden select element is not part of the form anyway. If I comment this block, then it works for me. I didn't tried $timeout solution suggested by @hodeyp (can you provide the code pls?). It has to resolve #1801 somehow, but I do not use it so cannot test.
+1 have the same issue. It's working in my application, but it's failing with this issue in my integration tests.
+1 @evoker I had this issue when using with ng-repeat too.
I found a workaround: http://stackoverflow.com/questions/14378401/dynamic-validation-and-name-in-a-form-with-angularjs
which uses outer form + inner form for each ng-repeat item
+1 same issue, hope this one get fixed soon.
+1
This appears to be caused by lack of a controller around the directive.
http://codepen.io/karlhorky/pen/OVZOqy
I've opened a PR: angular/material#3671