angular / angular.js

AngularJS - HTML enhanced for web apps!
https://angularjs.org
MIT License
58.89k stars 27.54k forks source link

Comprehension Expression in select directive should be a service #7888

Open mdedetrich opened 10 years ago

mdedetrich commented 10 years ago

The setupAsOptions defined here https://github.com/angular/angular.js/blob/master/src/ng/directive/select.js#L304

Should be refactored out as a service. The reasoning being is there may be other custom directives that use comprehension expressions, and they would essentially have to reimplement that function instead of requiring a service which is how its done for things like $parse

It would also help reduce the complexity of the code

tdakhla commented 10 years ago

+1

In the meantime, you can use this Angular Strap service to do the parsing, just as select would do: https://github.com/mgcrea/angular-strap/blob/master/src/helpers/parse-options.js.

samherrmann commented 9 years ago

:+1:

The angular-xeditable project also created its own parser service: https://github.com/vitalets/angular-xeditable/blob/d8b65839c2b11ff6ab4dbc4230dd33cb9d5b5e4e/src/js/helpers.js#L125

battlesnake commented 9 years ago

+1

reda-alaoui commented 9 years ago

+1

motofix commented 9 years ago

+1

battlesnake commented 9 years ago

I've created a DSL compiler that takes a domain-specific-language spec for a non-recursive text langauge and creates a RegExp for parsing expressions in that language.

It's at << https://github.com/kartulita/dsl >>, and if people are genuinely interested in it, then I'll document it and abstract it away from the framework that it was originally intended for.

An example with the ngOptions-style syntax is at:

https://github.com/kartulita/dsl/blob/master/list-comprehension-service.js

I know that this is totally useless at the moment for anyone who actually wants to use it as there's no demos or documentation, however I would be happy to produce the necessary docs if people really want a fast DSL parser generator.

The incomplete module dependency for that module is at << https://github.com/kartulita/transformations >>, if anyone actually is massochistic enough to try to run my code in its current state.