Angular ng-options 在加载时将 pristine 设置为 false

Angular ng-options setting pristine to false on load

选项表达式中 "multiple" 和 "as" 的以下组合使 ng-options 在首次加载表单时将 pristine 设置为 false。这是 angular 错误吗?有人知道解决方法吗?

http://plnkr.co/edit/c9ZIgiiisntkJJBeFFdy

<select multiple name="mySelect" id="mySelect"
      ng-options="option.id as option.name for option in data.availableOptions"
      ng-model="data.selectedOption"></select>

当您设置 data.selectedOption angular select 选项并将 pristine 设置为 false 时。

您可以使用 .$setPristine() 方法手动设置为真。

这是一个 angular 错误。

Yep, that looks like a bug. You don't need select as, but you need multiple. It's got something to do with us checking if the view / model has changed after the options have changed. When that's the case, we call $setViewValue with the new selection, which triggers a call to $setDirty. As a workaround you could add a directive that runs after ngOptions which forces $pristine = true and $dirty = false after the initial loading.

https://github.com/angular/angular.js/issues/13211