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>
<html>
<body><div ng-app=“myApp” ng-controller=“myCtrl”>
{{ firstName + ” ” + lastName }}
</div>

<script src=“//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js”></script>

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

</body>
</html>

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

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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