raduken
raduken

Reputation: 2119

Angular JS ng-include

I Followed that link to learn how to use: ng-include: http://www.w3schools.com/angular/angular_includes.asp

But I Have few questions and I not understand well how it works.

If I remove app1.js = the ng include will not works, why? I really not understand angular I am just trying for the first time.

app1.js

angular.module('myApp', []).controller('userCtrl', function($scope) {

})

as well if I am not running this code in a server will not works too, why?

html code:

<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> 

<body ng-app="myApp" ng-controller="userCtrl">

<div class="container">
  <div ng-include="'includes/content.html'"></div>
  <div ng-include="'includes/header.html'"></div>
</div>

<script src= "js/app1.js"></script>

</body>

</html>

Upvotes: 0

Views: 86

Answers (1)

Kalhan.Toress
Kalhan.Toress

Reputation: 21901

you use the <body ng-app="myApp" ng-controller="userCtrl">

After you remove the app1.js there is no controller to match with the ng-controller so there will be a error saying undefined controller (check the console),

and change the ng-app="myApp" to ng-app, if you keep the ng-app="myApp" then it will search for a module called myApp as angular.module('myApp', [])

remove the ng-controller directive and check it will work.

then whole think would be

<body ng-app>...

Upvotes: 1

Related Questions