Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run AngularJS example

Tags:

angularjs

I've done as described here: http://docs.angularjs.org/tutorial/step_00 but can't run the phonecat example as AngularJS. It runs like a bunch of html files. For example, the app/index-async.html page gives me following error in Chrome's console:

Uncaught Error: No module: myApp

This file contains

angular.bootstrap(document, ['myApp']);
like image 284
Paul Avatar asked Nov 23 '12 14:11

Paul


People also ask

What is AngularJS example?

AngularJS Example Example explained: AngularJS starts automatically when the web page has loaded. The ng-app directive tells AngularJS that the <div> element is the "owner" of an AngularJS application. The ng-model directive binds the value of the input field to the application variable name.

What is run method in AngularJS?

Run blocks are the closest thing in AngularJS to the main method. A run block is the code which needs to run to kickstart the application. It is executed after all of the services have been configured and the injector has been created.

How to run AngularJS project on Windows?

How to run AngularJS Project 1 Run angularJS project on web server. If you are running node.js: In your browser, navigate to http://localhost:8000/app/index.html 2 Running Xampp Webserver. In your browser, navigate to http://localhost:8000/app/index.html ... ... 3 Running Others WebServer. ... 4 Windows Command Line 5 On Git Bash window. ...

What are the different parts of an AngularJS application?

An AngularJS application consists of following three important parts − ng-app − This directive defines and links an AngularJS application to HTML. ng-model − This directive binds the values of AngularJS application data to HTML input controls.

What is the best way to start learning AngularJS?

The best way to see the power of an AngularJS Application is to create your first basic program “Hello World” app in Angular.JS. There are many integrated development environments you can use for AngularJS development, some of the popular ones are mentioned below.

How to run angular CLI on your system?

So, to run Angular CLI on your system, you should have Node.js in your system first. Node.js is for servers and to develop server-side applications, while Angular is a front end solution. Node.js helps you with Angular CLI only.


2 Answers

The bootstrap part needs to be called after the element you're bootstrapping to is loaded. You can either put the bootstrap code at the end of your html, or you can use something like document ready from JQuery.

like image 147
Ben Lesh Avatar answered Sep 27 '22 20:09

Ben Lesh


I had the same problem. When loading angular with reguirejs, you have to remove the ng-app directive from the html and add it after calling angular.bootstrap(document, ['myApp']) like this:

$(html).addClass('ng-app');

Check this seed project out: https://github.com/tnajdek/angular-requirejs-seed specifically index.html and app/js/main.js

like image 37
Martin Schaer Avatar answered Sep 27 '22 20:09

Martin Schaer