1

I know that due to backwards compatibility with IE, Angular allows the use of an xmlns and using ng: instead of ng-, however it doesn't appear to be working with all directives in xhtml

<?xml version="1.0"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ng="http://angularjs.org">
  <head>
    <title>Test</title>
  </head>
  <body ng:app="MyApp">
    <div ng:controller="FooController as foo">
      <p>{{foo.text}}</p>
    </div>
    <script src="angular.min.js" />
    <script>
      var app = angular.module("MyApp", []);
      app.controller("FooController", function () {
        this.text = "Hello Angular!";
      });
    </script>
  </body>
</html>

The above will just produce {{foo.text}}, but if I replace ng:app with ng-app (leaving ng:controller the way it is) everything works fine. I really like the consistency of using namespaces, so why doesn't ng:app work?

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
Electric Coffee
  • 11,733
  • 9
  • 70
  • 131

2 Answers2

1

The ng:app syntax doesn't work due to the following:

The elements contained within the template are always created in the HTML namespace. Whilst this is probably fine for the fast majority of cases if someone ever uses AngularJS with another XML document like SVG this could cause some problems.

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
0

Your example works fine. Have a look here: http://plnkr.co/edit/mgUMZe09FSr1aALE6ddd?p=preview

Maybe your angular script is not included properly

<script/> should be <script></script> its not self closing html tag

jonasnas
  • 3,540
  • 1
  • 23
  • 32
  • but the weird thing is that it works fine if I change the tag, I doubt it has anything to do with the inclusion of angular in some way – Electric Coffee Dec 04 '15 at 19:29
  • `` should be `` its not self closing html tag – jonasnas Dec 04 '15 at 19:32
  • you do realise I'm using XHTML right? in XHTML self-closing tags are allowed for all tags, also using the HTML-style doesn't work either in my browser, only changing from `ng:` to `ng-` seems to work – Electric Coffee Dec 04 '15 at 19:38
  • Good point. Anyway, xhtml and browser rendering is different question. Regarding angular everything works as expected – jonasnas Dec 04 '15 at 19:43
  • It works for me in Firefox 42 (OS X) as well if I copy paste plunker. Have a look at this (mime type) http://stackoverflow.com/questions/97522/what-are-all-the-valid-self-closing-elements-in-xhtml-as-implemented-by-the-maj – jonasnas Dec 04 '15 at 19:51
  • looked at it, it parses it as xhtml, still doesn't work if I write `ng:app` – Electric Coffee Dec 04 '15 at 19:56