malcoauri
malcoauri

Reputation: 12199

AngularJS application without web-server

I'm a newby in AngularJS, and I have one question: because Angular is client-side framework, it must work without any web-server, but this code doesn't work:

<!doctype html>
<html ng-app="learningApp">
  <body>
    I can add: {{ 1+2 }}.
    <script src="angular.min.js"></script>
  </body>
</html>

I see just "I can add: {{ 1+2 }}." in the browser window. What's the trouble? Thanks.

Upvotes: 0

Views: 268

Answers (1)

Ansuman Bebarta
Ansuman Bebarta

Reputation: 7266

The problem is that you are using "learningApp" but you are not including any javascript having learningApp. If you open the page in firefox and then check firebug you will get following error which complains about not finding "learningApp":

Error: [$injector:modulerr] http://errors.angularjs.org/1.2.26/$injector/modulerr?p0=learningApp&p1=%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.2.26%2F%24injector%2Fnomod%3Fp0%3DlearningApp%0AC%2F%3C%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A6%3A443%0AZc%2Fb.module%3C%2F%3C%2Fb%5Be%5D%3C%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A21%3A1%0AZc%2Fb.module%3C%2F%3C%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A20%3A376%0Ae%2F%3C%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A33%3A265%0Ar%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A7%3A288%0Ae%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A33%3A207%0Agc%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A36%3A307%0Afc%2Fc%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A18%3A168%0Afc%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A18%3A380%0AXc%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A17%3A422%0A%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A215%3A30%0Aa%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A145%3A67%0Aoe%2Fc%2F%3C%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A31%3A223%0Ar%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A7%3A288%0Aoe%2Fc%40file%3A%2F%2F%2Fhome%2Fansumanb%2FDesktop%2Flogin_with_angular%2Fexisting%2Flib%2Fangular%2Fangular.min.js%3A31%3A207%0A


...N.stringify(arguments[c]):arguments[c]);return Error(a)}}function Pa(b){if(null=...

Just remove learningApp, as you are not including one, it will work. (DEMO)

<!doctype html>
<html ng-app>
  <body>
    I can add: {{ 1+2 }}.
    <script src="angular.min.js"></script>
  </body>
</html>

Or else you can create an app.js and include the js. (DEMO)

<!doctype html>
<html ng-app="learningApp">
  <body>
    I can add: {{ 1+2 }}.
    <script src="angular.min.js"></script>
    <script src="app.js"></script>
  </body>
</html>

Have following in app.js

angular.module('learningApp', []);

Upvotes: 1

Related Questions