0

We currently have some hardcoded code:

ng-form class="form-horizontal" name="genderForm">
      <div data-fields="">
        <div class="form-field-gender control-group form-field" data-field="">
          <div class="controls" data-input="">
            <label class="radio">
              <input type="radio" ng-model="appuser.traits[6]" ng-value= "[42198]" name="field-input-gender" id="field-input-gender-0" required>
              <i class="fa fa-male fa-fw"></i> {{genderQuestion.traits[0].value_text}}
            </label>
            <label class="radio">
              <input type="radio" name="field-input-gender" ng-model="appuser.traits[6]" id="field-input-gender-1" ng-value="[42199]" required>
              <i class="fa fa-female fa-fw"></i> {{genderQuestion.traits[1].value_text}}
            </label>
          </div>
          <div class="controls">
            <div class="text-error" data-error="">
            </div>
          </div>
        </div>
      </div>

    </ng-form>

Ideally it will be dynamic so it should be something like this:

ng-form class="form-horizontal" name="genderForm">
      <div data-fields="">
        <div class="form-field-gender control-group form-field" data-field="">
          <div class="controls" data-input="">
            <label class="radio">
              <input type="radio" ng-model="appuser.traits[{{genderQuestion.id}}]" ng-value= "[{{genderQuestion.traits[0].id}}]" name="field-input-gender" id="field-input-gender-0" required>
              <i class="fa fa-male fa-fw"></i> {{genderQuestion.traits[0].value_text}}
            </label>
            <label class="radio">
              <input type="radio" name="field-input-gender" ng-model="appuser.traits[6]" id="field-input-gender-1" ng-value="[{{genderQuestion.traits[1].id}}]" required>
              <i class="fa fa-female fa-fw"></i> {{genderQuestion.traits[1].value_text}}
            </label>
          </div>
          <div class="controls">
            <div class="text-error" data-error="">
            </div>
          </div>
        </div>
      </div>

    </ng-form>

But something about going from ng-model="appuser.traits[6]" to ng-model="appuser.traits[{{genderQuestion.id}}]" and ng-value="[42199]" to ng-value="[{{genderQuestion.traits[1].id}}]" seems to make it spazz out and not resolve any of the {{}} fields.

Any idea where I'm going wrong? Technically genderQuestion.id = 6 and genderQuestion.traits[1].id = 42199 but in this format it doesn't seem to like those.

Maybe I'm missing like a toString format or something?

2
  • You don't need {{ }} again to be evaluated appuser.traits[genderQuestion.id] should work. Commented May 3, 2017 at 21:58
  • That definitely did it. Want to add it as an answer and I'll accept? :) Commented May 11, 2017 at 3:17

1 Answer 1

1

2 way data binding with the ngModel directive doesn't need {{ }} again. You can directly refer to the scope object with genderQuestion.id appuser.traits[genderQuestion.id].

Ta

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.