This is similar to #10037. Is it currently achievable with 1.4.0-beta.5?
If there's currently no way to reference the field (actually I think "pass" the field because ng-messages-include and the field itself are not really linked in anyway, just they usually appear one after the other in DOM) it would be nice to have especially in the light of the new dynamic ng-messages: #10676
You can currently achieve this, but without reusing messages in
ng-messages-include:<input name="field1" type="number" ng-model="myForm.field1">
<div ng-messages="myForm.field1.$error">
<span ng-message="backend">{{ backendErrors['field1'] }}</span>
<ng-messages-include src="msgs.html"></ng-messages-include>
</div>
<input name="field2" type="number" ng-model="myForm.field2">
<div ng-messages="myForm.field2.$error">
<span ng-message="backend">{{ backendErrors['field2'] }}</span>
<ng-messages-include src="msgs.html"></ng-messages-include>
</div>
I assume a simple implementation would be to just pass the field object to
ng-messages-include:<ng-messages-include src="msgs.html" field="myForm.field1"></ng-messages-include>
And then just use use the
field object in the msgs.html file:<span ng-message="backend">{{ backendErrors[field.$name] }}</span>
And in controller you'd just manipulate these:
$scope.myForm.field1.$error = {'backend': true}
$scope.backendErrors['field1'] = 'Dynamic error'