Saturday, 15 September 2012

angularjs - use filter in angular directive to change collection in ng-options -


Start of a selection To set up the 10 most used languages, Have the following instructions and set a custom CSS class:

  app.directive ('sortTopLocales', function ($ timeout)) {// Selected from angled (get an array of ng-options For Var) NG_OPTIONS_REGEXP = / ^ (*.?) \ S * (: \ s + as + s + (*).)? (+: ([\ $ \ W] [\ $ \ W] *) | (? \ (\ \ \ \ \) For \ + s + (: (+: \ s + group \ s + \ s + + (*)) * ([\ $ \ W] [\ $ \ w] *) *, \ s * ([\ $ \ w] [\ $ \ w] *) \))) \ s + S * (*) (:?? \ S + track \ s + by + s (*.?)) $$ /; Var Top 10 Language = ['n', 'zhu', 's', 'ja', 'pt', 'd', 'r', 'fr', 'ru', 'ko']; Var top10languagesReversed = top10languages.reverse (); Var cssClass = 'top10'; Refund {Restrict: 'A', Link: Function (Scope, Element, ethers) {If (ethers.nogopations) {var match = attrs.ngOptions match (NG_OPTIONS_REGEXP); Scope $ WatchCollection (match [7], function (locales) {var already severed = element.find ('option.' + CssClass) Length; if (angular Unified (locale) has already been removed) {return; } Var top10Index = 0; $ Timeout (function () {element.find ('option.' + CssClass) .removeClass (cssClass); // Reset CSS class angular.forEach (reverse in top 10 languages, function (locale) {var index = locales.indexOf (Locale); if (index! == -1) {locales.splice (index, 1); // removes it from the array locus. The horoscope (//) sets it to array option option = Element.find (option [value = '+ top 10 index +']) option; adlas (css class); top 10 index ++;}}); console.log (scope. Avel (match [7]) [ 0], Locale [0]); // without filter = & gt; 'N', 'A Filters with no '// =>' A ',' N '}); }); }}}; });  

It works as expected without filters, but it does not happen when I use a filter in ng-options :

Function:

ng-option = "Locale for locale in locale" // match [7] = 'locale'

not working Is doing:

ng-option = "locale for locale in locale | orderBy" // match [7] = 'locale |

The changed array has a different output and $ watchCollection expression.

  scope $ Eval (match [7]) [0] // 'A' locale [0] // 'n'  

When I use filters within the directive code and in HTML If not, the array is not updated.

So basically my question is: How do I change an array with filter in $ watchCollection to use it in NG-Options?


No comments:

Post a Comment