Error: [ngModel:nonassign] Expression is non-assignable

Pindakaas picture Pindakaas · Jun 12, 2014 · Viewed 44k times · Source

Trying to display a columnvalue from a gridcollection based on another value in that same row. The user can select/change values in a modal which contains a grid with values. When the modal closes the values are passed back. At that moment I would like to set a value for 'Also known as':

html:

 Also known as: <input type="text" `ng-model="displayValue(displayNameData[0].show,displayNameData[0].value)">`

I created a function on scope to select the value only when the 'show' value is true:

$scope.displayValue = function (show, val) {
    if (show) {
        return val;
    }
    else {
        return '';
    }
}

However when I close the modal I get an error:

Error: [ngModel:nonassign] Expression 'displayValue(displayNameData[0].show,displayNameData[0].value)' is non-assignable. 

plnkr reference:http://plnkr.co/edit/UoQHYwAxwdvX0qx7JFVW?p=preview

Answer

Mike Becatti picture Mike Becatti · Aug 8, 2015

Using ng-value instead of ng-model worked for me.