This is the continuation from AngularJS Recipe: Part 4.
# Modules in AngularJS
Here in this example I am showing the model and controller in separate files.
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AngularJS_Demo.Default" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
- <script src="myApp.js"></script>
- <script src="employeeController.js"></script>
- </head>
- <body>
- <div ng-app="myApp" ng-controller="employeeController">
- <table style="border: 4px solid red; background-color: skyblue; color: blue;" border="1">
- <tr ng-repeat="x in Emp_Names">
- <td style="width: 200px;">{{ x.name }}</td>
- <td style="width: 200px;">{{ x.country }}</td>
- </tr>
- </table>
- </div>
- </body>
- </html>
- app.controller("employeeController", function ($scope) {
- $scope.Emp_Names = [
- { name: 'Shambhu Sharma', country: 'USA' },
- { name: 'Rahul Saxena', country: 'India' },
- { name: 'Abhishek Nigam', country: 'USA' },
- { name: 'Shraddha Gaur', country: 'India' },
- { name: 'Shweta Kashyap', country: 'India' },
- { name: 'Yogesh Gupta', country: 'USA' },
- { name: 'Rakesh Dixit', country: 'India' },
- { name: 'Manu Khanna', country: 'India' },
- { name: 'Saurabh Mehrotra', country: 'USA' },
- { name: 'Mayank Dhulekar', country: 'USA' },
- { name: 'Akhilesh Atwal', country: 'India' }
- ];
- });
- var app = angular.module("myApp", []);

# Making a Registration Form with input text and button
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AngularJS_Demo.Default" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
- <script>
- var app = angular.module('myApp', []);
- app.controller('formCtrl', function ($scope) {
- $scope.master = { Name: "Rahul Saxena", Email: "[email protected]", Password: "PWD", City: "Noida", Country: "India", Mobile: "958100000" };
- $scope.reset = function () {
- $scope.user = angular.copy($scope.master);
- };
- $scope.reset();
- });
- </script>
- </head>
- <body style="background-color: skyblue; color: blue; font-family: Arial; font-size: 12pt; font-weight: bold;">
- <div ng-app="myApp" ng-controller="formCtrl">
- <form novalidate>
- <table>
- <tr>
- <td>Name:
- </td>
- <td></td>
- <td>
- <input type="text" ng-model="user.Name"></td>
- </tr>
- <tr>
- <td>Email:
- </td>
- <td></td>
- <td>
- <input type="text" ng-model="user.Email"></td>
- </tr>
- <tr>
- <td>Password:
- </td>
- <td></td>
- <td>
- <input type="text" ng-model="user.Password"></td>
- </tr>
- <tr>
- <td>City:
- </td>
- <td></td>
- <td>
- <input type="text" ng-model="user.City"></td>
- </tr>
- <tr>
- <td>Country:
- </td>
- <td></td>
- <td>
- <input type="text" ng-model="user.Country"></td>
- </tr>
- <tr>
- <td>Mobile:
- </td>
- <td></td>
- <td>
- <input type="text" ng-model="user.Mobile"></td>
- </tr>
- <tr>
- <td></td>
- <td></td>
- <td>
- <button ng-click="reset()">RESET</button></td>
- </tr>
- </table>
- </form>
- <p>Current Form Value = {{user}}</p>
- <p>Master Value = {{master}}</p>
- </div>
- </body>
- </html>


# Creating a Registration Form with Validation
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AngularJS_Demo.Default" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
- <script>
- var app = angular.module('myApp', []);
- app.controller('validateCtrl', function ($scope) {
- $scope.user = 'Rahul Saxena';
- $scope.email = '[email protected]';
- $scope.password = 'PWD';
- $scope.city = 'Noida';
- $scope.country = 'India';
- $scope.mobile = '9581000000';
- });
- </script>
- </head>
- <body style="background-color: skyblue; color: blue; font-family: Arial; font-size: 12pt; font-weight: bold;">
- <form ng-app="myApp" ng-controller="validateCtrl"
- name="myForm" novalidate>
- <table>
- <tr>
- <td>Name:
- </td>
- <td></td>
- <td>
- <input type="text" name="user" ng-model="user" required>
- <span style="color: red" ng-show="myForm.user.$dirty && myForm.user.$invalid">
- <span ng-show="myForm.user.$error.required">Username is required.</span>
- </span>
- </td>
- </tr>
- <tr>
- <td>Email:
- </td>
- <td></td>
- <td>
- <input type="email" name="email" ng-model="email" required>
- <span style="color: red" ng-show="myForm.email.$dirty && myForm.email.$invalid">
- <span ng-show="myForm.email.$error.required">Email is required.</span>
- <span ng-show="myForm.email.$error.email">Invalid email address.</span>
- </span>
- </td>
- </tr>
- <tr>
- <td>Password:
- </td>
- <td></td>
- <td>
- <input type="text" name="password" ng-model="password" required>
- <span style="color: red" ng-show="myForm.password.$dirty && myForm.password.$invalid">
- <span ng-show="myForm.password.$error.required">Password is required.</span>
- </span>
- </td>
- </tr>
- <tr>
- <td>City:
- </td>
- <td></td>
- <td>
- <input type="text" name="city" ng-model="city" required>
- <span style="color: red" ng-show="myForm.city.$dirty && myForm.city.$invalid">
- <span ng-show="myForm.city.$error.required">City is required.</span>
- </span>
- </td>
- </tr>
- <tr>
- <td>Country:
- </td>
- <td></td>
- <td>
- <input type="text" name="country" ng-model="country" required>
- <span style="color: red" ng-show="myForm.country.$dirty && myForm.country.$invalid">
- <span ng-show="myForm.country.$error.required">Country is required.</span>
- </span>
- </td>
- </tr>
- <tr>
- <td>Mobile:
- </td>
- <td></td>
- <td>
- <input type="text" name="mobile" ng-model="mobile" required>
- <span style="color: red" ng-show="myForm.mobile.$dirty && myForm.mobile.$invalid">
- <span ng-show="myForm.mobile.$error.required">Mobile is required.</span>
- </span>
- </td>
- </tr>
- <tr>
- <td></td>
- <td></td>
- <td>
- <input type="submit"
- ng-disabled="myForm.user.$dirty && myForm.user.$invalid ||
- myForm.email.$dirty && myForm.email.$invalid ||
- myForm.password.$dirty && myForm.password.$invalid ||
- myForm.city.$dirty && myForm.city.$invalid ||
- myForm.country.$dirty && myForm.country.$invalid ||
- myForm.mobile.$dirty && myForm.mobile.$invalid" />
- </td>
- </tr>
- </table>
- </form>
- </body>
- </html>





Rahul Kumar SaxenaPosted Jul 8, 2015, 10:33 PM
Thanks Rakesh Chavda
RakeshPosted Jul 8, 2015, 2:50 PM
Good explain sir
Rahul Kumar SaxenaPosted Jul 8, 2015, 2:42 PM
Thanks.Santhakumar Munuswamy
Rahul Kumar SaxenaPosted Jul 8, 2015, 2:42 PM
Thanks.Jacob Robinson
Rahul Kumar SaxenaPosted Jul 8, 2015, 2:42 PM
Thanks Vikas Tyagi
Jacob RobinsonPosted Jul 7, 2015, 6:11 AM
Nice Article..
Vikas TyagiPosted Jul 7, 2015, 1:38 AM
Good work,
Santhakumar MunuswamyPosted Apr 28, 2015, 2:50 PM
Thanks for nice article. keep it up..
Santhakumar MunuswamyPosted Apr 28, 2015, 2:50 PM
Good work
Rahul Kumar SaxenaPosted Apr 28, 2015, 11:58 AM
Thanks Karthik Muthu Karuppan
Karthik Muthu KaruppanPosted Apr 28, 2015, 11:41 AM
Thanks for sharing
Rahul Kumar SaxenaPosted Apr 28, 2015, 4:01 AM
Thanks Nitin Tyagi
NitinPosted Apr 28, 2015, 1:05 AM
Good show