22

I'm newbie to angularjs. When I read the docs, I found it uses ng as prefix of attributes:

<body ng:controller="PhoneListCtrl">
  <ul>
    <li ng:repeat="phone in phones">
      {{phone.name}}
      <p>{{phone.snippet}}</p>
    </li>
  </ul>
</body>

I want to know if I can modify it as another word, such as x? Since I think x is much easier to type than ng.

1
  • 2
    You could fork it, and 'ng' with 'x' replace, then do git rebase ;-) Commented Jun 11, 2012 at 22:03

1 Answer 1

26

Since v1.0.0rc1, these are all equivalent:

<div ng-show="isVisible">Using ng-show</div>
<div ng:show="isVisible">Using ng:show</div>
<div data-ng-show="isVisible">Using data-ng-show</div>
<div x-ng-show="isVisible">Using x-ng-show</div>
<div class="ng-show:isVisible">Using class="ng-show:isVisible"</div>

Here's working fiddle: http://jsfiddle.net/vojtajina/Fgf3Q/

However, the main reason behind this was allowing valid html. So, you ca use x-* prefix for your custom directives, but not for Angular ones.

Check out docs for more info.

Sign up to request clarification or add additional context in comments.

7 Comments

Although this is not exactly what I want -- I hope to use x-show instead of ng-show, but I learn more about angularjs, thank you!
I kind of expected x:* to work (after setting xmlns:x="angularjs.org"), but it doesn't...
Does data-x-mydirective work? (x-mydirective is not valid HTML5?)
data-mydirective works and is valid html5, why would you need data-x-mydirective ?
That said, I think somebody should create a better html validator that can understand Angular stuff. Using data-* makes the templates awfull and only causes to "skip" these attributes as valid. Would be better to actually validate even the Angular attributes and produce errors like "you misspelled ng-rrepeat". It's not simple, but somebody should try it ;-)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.