Bhoomtawath Plinsut
Bhoomtawath Plinsut

Reputation: 1370

Are there convention for directive parameter?

I saw many directives that use a string as a parameter like ng-repeat, or angular-bootstrap. But it is difficult to validate or extract values from the parameter.

I think that an object literal as a parameter is a better option, but I rarely see any directive that is implemented this way.

I wonder if an object literal as a parameter considered a bad practice. Are their any convention about this?

Upvotes: 0

Views: 35

Answers (1)

Polochon
Polochon

Reputation: 2219

There is no convention about the type of parameters, the ng-class directive for example take an object and it's work fine.

Use a string is more friendly and clean to use, however it's harder to use in the code. Use an object is sometimes usefull and easier to use than a string but it's harder to read in the view.

Upvotes: 1

Related Questions