angular/angular.js — pull request #9285 by pocesar (2014-09-26 05:29:58+00:00)
Title: feat(selectDirective): add $optionChangeListeners to selectDirective controller

Adds `$optionChangeListeners` to the selectDirective controller, this is fully backward compatible and has no impact on performance whatsoever if the dev decides not to use it, and has no impact on existing code.

The reasoning behind this feature is that `ng-options` expression is un$parseable from outside the `optionDirective`, and you can't have the current set resulting from the `ng-options` expressions without relying on a scope. This forces the dev to create a custom directive to watch for changes on a `filtered` variable from the underlaying scope (like `ng-options="item.text for item in (filtered = (items | filter:fn1 | filter:fn2))" and it's not portable between directives, like `$viewChangeListeners` in `NgModelController`.
This makes isolated select controllers easier to accomplish and scope agnostic, aka web components style.

This also encourages future proof directive code, since it won't depend on the DOM or manually crafted enforced scopes.

Pseudo-code:

```js
.directive('selectPlugin', function(){
return {
restrict: 'A',
require: 'select',
link: function(scope, el, attrs, select){
select.$optionChangeListeners.push(function selectListener(items){
if (el.selectPlugin.initialized) {
el.selectPlugin.refresh();
} else {
el.selectPlugin.init();
}
});
}
};
});
```

```html

```

Closes #9222