Saturday, 7 May 2016

Bind Model in AngularJS with Example.

Creating a Module

A module is created by using the AngularJS function angular.module


Adding a Controller

Add a controller to your application, and refer to the controller with the ng-controller directive:


Example:- 

Step :- 1  --- Add HTML Page in Application.

Step :- 2  --- Add Angular JS file into  Application.

Step :- 3 --- then create path of anular.js.min file on HTML Page.


//----------AppJS Source Code-----------------

var appUI = angular.module("appUI", []);

appUI.controller("appCtrl", function ($scope) {
    $scope.firstName = "VICKY";
    $scope.lastName = "RAJ";

});



//----------Source Code-----------------

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../AppJS/angular.min.js"></script>
    <script src="../AppJS/firstApp.js"></script>
</head>
<body ng-app="appUI" ng-controller="appCtrl">
    <div>
        <div>
            <table align="center">
                   <tr><td>Enter First Name</td><td><input type="text" ng-model="firstName" placeholder="First Name" /></td></tr>
                   <tr><td>Enter Last Name</td><td><input type="text"  ng-model="lastName" placeholder="Last Name" /></td></tr>
                  <tr><td>First Name</td><td >{{firstName}}</td></tr>
                  <tr><td>Last Name</td><td>{{lastName}}</td></tr>
            </table>
        </div>
    </div>
</body>

</html>

---------------------------------------------------------------------------------------------





No comments:

Post a Comment

Factorial of a Number

Recently Viewed