ngModel's $pristine state not updated when changes come from model
Hi.
In angular's src here, it seems that ngModel's $pristine state only changes when $setViewValue() is invoked. Since $setViewValue() is only invoked when changes come from view (e.g. when users type in the input box), $pristine state is not updated when changes come from model (as in here).
My use case:
<input type="text" ng-model="data.a" />
<input type="text" ng-model="data.b" ng-change="doSomething()" />
$scope.doSomething = function() {
$scope.a = $scope.b; // changes "$scope.a" from model
};
When user types in the second input, the first input's content changes correspondingly. This is correct. But the first input's $pristine state is not updated (still $pristine=true).
Is this something we need to fix? Or am i misunderstanding the meaning of $pristine?
Huge thanks for creating angular!
$pristine means that a user didn't interact with a given control through UI yet. It is not meant to change on model mutations.
It's werid!
@pkozlowski-opensource Thanks for answering. But what if i wanna know if some kind of indirect interactions with a control has happened, like in my use case? If $pristine is not meant for that, does angular have some builtin states for that?
@cxyokk no, but you can easily achieve this by $watching your model.