Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Declarative Attribute Enum #11140

Open
vitaly-t opened this issue Feb 22, 2015 · 1 comment
Open

Declarative Attribute Enum #11140

vitaly-t opened this issue Feb 22, 2015 · 1 comment

Comments

@vitaly-t
Copy link

  • It would allow for improvement in modern editors, like Webstorm, to parse a directive and list supported attribute values.
  • It would allow Angular to parse such attributes when encountering the containing directive and produce a meaningful error when needed, as opposed to letting each directive deal with it. In fact, Angular would even be able to parse the attribute value dynamically when it is used through a model as opposed to static string.
  • With the right approach enum-s could be extended to contain both value, and id and a text description, like a self-documenting look-up dictionary. This would be awesome.

Example.

app.directive('food', [function () {
    return {
        scope: {
            type: [
                {
                    $id: 1,
                    $value: 'fruit',
                    $doc: 'bla-bla'
                },
                {
                    $id: 2,
                    $value: 'vegetable',
                    $doc: 'bla-bla'
                }]
        },
        restrict: 'E',
        link: function (scope) {
            /* automatically extending scope.type with: $id, $value, $doc, $index */
            switch (scope.type.$value) {
                case 'fruit':
                    break;
                case 'vegetable':
                    break;
                default:
                    /* Will never get here because Angular won't let it */
                    break;
            }
        }
    }
}]);
@pkozlowski-opensource
Copy link
Member

Yeh, but what you are really asking for here is a regular type system... It would be interesting to see how much millage we can get from adopting types (AtScript, TypeScript or similar) for this use-case...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants