Skip to content

Directive input and options naming convention #759

Open
@alirezamirian

Description

@alirezamirian

One of the things that I think can be a source of confliction and non-readability in angular 1 is that attributes can be used as both directives (normally behavioural directives) and inputs for directives. The latter can be an isolated scope binding or something used like scope.$eval(attrs.someOptionsForFooDirective) inside some directive's link function.
So when you see something like this:

<img ns-lazy-src="images/foo.png" delay="100" /> 

It's not obvious that ns-lazy-src is a directive and delay is an input for that directive.
Some directive writers use namespace also for directive options and inputs:

<img ns-lazy-src="images/foo.png" ns-delay="100" />

While it solves the problem of naming collision and it's definitely better than not using the namespace for directive's inputs and options, the problem of non-readability still exists.

I think a naming convention for options and inputs of directive makes everything cleaner.
I haven't thought about the best style but maybe inputs of directives (I mean isolated bindings) can be prefixed with in- and options of directive can be prefixed with opt-

<img ns-lazy-src="images/foo.png" opt-delay="100" />

However it may introduce a confliction probability!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions