0

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>
1
  • When you are removing app1.js are you also dropping the ng-app and ng-controller? Commented Sep 30, 2015 at 11:53

1 Answer 1

1

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>...
Sign up to request clarification or add additional context in comments.

3 Comments

i did and i got this error: Uncaught Error: [$injector:modulerr] errors.angularjs.org/1.3.14/$injector/……gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A17%3A381)
you should also remove ng-app="myApp" and just leave ng-app, because when you remove app.js, a reference to myApp is also removed.
oh yeas remove as @Jahongir said ill update the answer thanks for pointing it out :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.