using dash in directive

2,084 views
Skip to first unread message

Wee Ching Chok

unread,
Apr 1, 2013, 12:42:27 AM4/1/13
to ang...@googlegroups.com
I create a directive with
app.directive("foo-bar", function(){
      restrict: "E"
      ..............
);

in html
<foo-bar></foo-bar>  not working


It only works when i remove the dash.
directive("foobar",....)
<foobar></foobar>

So does actually angularjs support dash?
But it listed in official docs

Josh David Miller

unread,
Apr 1, 2013, 1:28:21 AM4/1/13
to angular
Hello!

Directive and attribute names are supposed to follow the naming rules and conventions of JavaScript variables as they are sometimes turned into them. "foo-bar" can't be a JavaScript variable name, so we use camelCase to indicate where in HTML the element or attributes should be hyphenated. E.g. "fooBar" becomes "foo-bar". Directive names are translated in *both* directions (from HTML to JavaScript and from JavaScript to HTML) so "foo-bar" would be ambiguous at best as well as totally non-functional as an attribute.

Josh


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Wee Ching Chok

unread,
Apr 1, 2013, 9:53:53 AM4/1/13
to ang...@googlegroups.com
Thanks for your explanation
Reply all
Reply to author
Forward
0 new messages