Shohel
Shohel

Reputation: 3934

Assign value from one ng-model to other ng-model

I have two ng-repeat, now I want to add this into my second ng-repeat, I have written the code below:

<ul>
      <li data-ng-repeat="quotTypeOpt in list1">
        <label>{{quotTypeOpt.text}}</label>
        <ul>
          <li data-ng-repeat="quotTyp in quotTypeOpt.list2">
            <div ng-model="quotTyp.value = quotTypeOpt.value"></div>
            <input type="text" ng-model="quotTyp.text" />
            <label>{{quotTyp.value}}</label>
          </li>
        </ul>
      </li>
    </ul>

When I add line by this way ng-model="quotTyp.value = quotTypeOpt.value", then error has been occured but need is asign value from quotTypeOpt.value to quotTyp.value

Error: [ngModel:nonassign] Expression 'quotTyp.value = quotTypeOpt.value' is non-assignable

Plunker

Thanks

Upvotes: 2

Views: 1302

Answers (1)

Manish Kr. Shukla
Manish Kr. Shukla

Reputation: 4477

You're trying to initialize some variable. The best place to do so is ng-init.

So in your code, it goes like this :

    <ul>
        <li data-ng-repeat="quotTypeOpt in list1">
            <label>{{quotTypeOpt.text}}</label>
            <ul>
                <li data-ng-repeat="quotTyp in quotTypeOpt.list2">
                    <div ng-model="quotTyp.value" ng-bind="quotTyp.value = quotTypeOpt.value"></div>
                    <input type="text" ng-model="quotTyp.text" />
                    <label>{{quotTyp.value}}</label>
                </li>
            </ul>
        </li>
    </ul>

Upvotes: 1

Related Questions