0
<!DOCTYPE html>
<html >
<head>
    <title>Angular ToDo</title>
    <script src="script/angular.js"></script>
    <script src="script/script.js"></script>

</head>
<ng-app>
<body>
 {{6+4}}

Is this a valid angular syntax? Can I use ng-app as an element ?

3 Answers3

2

No, you have to place it inside an element.

You can find valid examples here: http://www.w3schools.com/angular/ng_ng-app.asp

Rick
  • 1,224
  • 3
  • 13
  • 27
  • 1
    Correct. From the [documentation](https://docs.angularjs.org/api/ng/directive/ngApp): _The ngApp directive designates the **root element** of the application and is typically placed near the root element of the page - e.g. on the or tags._ – Alon Eitan Apr 17 '16 at 17:27
1

No. The documentation specifies ng-app is restricted explicitly to attributes.

<ANY
  ng-app="angular.Module"
  [ng-strict-di="boolean"]>
...
</ANY>

In Angular's documentation, ANY refers to any element that is either defined in HTML5 or defined by your own element directive.

If you want it in a specific spot, it's been conventional to place it within the container of that portion of your application, whether that's a div or some other element.

Makoto
  • 104,088
  • 27
  • 192
  • 230
0

I don't think you can do this nor am I sure what you're trying to accomplish. If it is to use more than one Angular module in the same HTML page here is a post that should help.

http://www.simplygoodcode.com/2014/04/angularjs-getting-around-ngapp-limitations-with-ngmodule/

dvanderl
  • 59
  • 5