AngularJs – Part Six

Its time to build application now. So far we covered model,view and controller clearly in above tutorials.

Your application should have at least one module file, and one controller file for each controller.

Lets revise with old example..

First create a module file “myApp.js”:

var app = angular.module(“myApp”, []);

Then create the controller file(s). In this case “myCtrl.js”:

app.controller(“myCtrl”, function($scope) {
$scope.firstName = “John”;
$scope.lastName = “Doe”;

Finally, edit your HTML page:

AngularJS Example

<!DOCTYPE html>
<body><div ng-app=“myApp” ng-controller=“myCtrl”>
{{ firstName + ” ” + lastName }}

<script src=“//”></script>

<script src=“myApp.js”></script>
<script src=“myCtrl.js”></script>


Output: John Doe
Dont forget to see next post with another example :).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s