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>
employeeController.js
- 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' }
- ];
- });
myApp.js
- 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