I played a little with your code and found that the reason the error occurred was because the third question received more answers than the second, so when you create mdRadioGroup, for the first time it determines 4 $ index answers, and then for question 3 it comes out of 6 answers ... Thus, it is not an elegant solution to create as many $ index as possible than the maximum number of answers to any question, for the first time only those that have text are shown ...
.directive('question', function($compile) { var combo = '<div>COMBO - {{content.text}}</div>'; var radio = [ '<div>RADIO - {{content.text}}<br/>', '<md-radio-group layout="row">', '<md-radio-button ng-repeat="a in content.answers track by $index" ng-show={{a.text!=""}} value="{{a.text}}" class="md-primary">{{a.text}}</md-radio-button>', '</md-radio-group>', '</div>' ].join(''); var input = [ '<div>INPUT - {{content.text}}<br/>', '<md-input-container>', '<input type="text" ng-model="color" aria-label="{{content.text}}" required md-maxlength="10">', '</md-input-container>', '</div>' ].join(''); var getTemplate = function(contentType) { var template = ''; switch (contentType) { case 'combo': template = combo; break; case 'radio': template = radio; break; case 'input': template = input; break; } return template; }
then change the questions to have the maximum number of answers each time in all questions:
$scope.questions = [{ type: 'radio', text: 'Question 1', answers: [{ text: '1A' }, { text: '1B' }, { text: '1C' }, { text: '' }, { text: '' }, { text: '' }, { text: '' }] }, { type: 'input', text: 'Question 2', answers: [{ text: '2A' }, { text: '2B' }, { text: '2C' }, { text: '' }, { text: '' }, { text: '' }, { text: '' }] }, { type: 'radio', text: 'Question 3', answers: [{ text: '3A' }, { text: '3B' }, { text: '3C' }, { text: '3D' }, { text: '' }, { text: '' }, { text: '' }] }, { type: 'combo', text: 'Question 4', answers: [{ text: '4A' }, { text: '4B' }, { text: '' }, { text: '' }, { text: '' }, { text: '' }, { text: '' }] }];
The rest of the code is the same. As I said, there are no elegant ones and there are probably better options, but it may be a solution at the moment ...