Tom Hammond
Tom Hammond

Reputation: 6080

Angular Rails Not Resolving

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?

Upvotes: 0

Views: 26

Answers (1)

Searching
Searching

Reputation: 2279

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

Upvotes: 1

Related Questions