This is the continuation of AngularJS Recipe - Part 2.
AngularJS Recipe: Part 2
# Showing Data in a Table after reading from Controller external File
The following is my external Controlller file.
- ngular.module('myApp', []).controller('employeeCtrl', function ($scope) {
- $scope.Emp_Names = [
- { name: 'Rahul Saxena', country: 'India' },
- { name: 'Shambhu Sharma', country: 'USA' },
- { name: 'Abhishek Nigam', country: 'USA' },
- { name: 'Yogesh Gupta', country: 'USA' },
- { name: 'Rakesh Dixit', country: 'India' },
- { name: 'Manu Khanna', country: 'India' },
- { name: 'Saurabh Mehrotra', country: 'USA' },
- { name: 'mayank Dhulekar', country: 'India' }
- ];
- });
- <%@ 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="employeeController.js"></script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div ng-app="myApp" ng-controller="employeeCtrl">
- <table style="border:1px solid;" 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>
- </form>
- </body>
- </html>
# Showing Record from External Controller File in a Table with CSS style sheet:
The following is my external Controlller file.
- angular.module('myApp', []).controller('employeeCtrl', 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' }
- ];
- });
- <%@ 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>
- <style>
- table, th, td {
- border: 1px solid grey;
- border-collapse: collapse;
- padding: 5px;
- }
- table tr:nth-child(odd) {
- background-color: red;
- color:yellow;
- font-family:Verdana;
- }
- table tr:nth-child(even) {
- background-color: blue;
- color:white;
- font-family:Arial;
- }
- </style>
- <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
- <script src="employeeController.js"></script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div ng-app="myApp" ng-controller="employeeCtrl">
- <table style="border: 1px solid;" 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>
- </form>
- </body>
- </html>
# Showing Records In a Table with Index Value:
The following is my external Controlller file.
- angular.module('myApp', []).controller('employeeCtrl', 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' }
- ];
- });
- <%@ 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>
- <style>
- table, th, td {
- border: 1px solid grey;
- border-collapse: collapse;
- padding: 5px;
- }
- table tr:nth-child(odd) {
- background-color: red;
- color: yellow;
- font-family: Verdana;
- }
- table tr:nth-child(even) {
- background-color: blue;
- color: white;
- font-family: Arial;
- }
- </style>
-
- <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
- <script src="employeeController.js"></script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div ng-app="myApp" ng-controller="employeeCtrl">
- <table style="border: 1px solid;" border="1">
- <tr ng-repeat="x in Emp_Names">
- <td>{{ $index + 1 }}</td>
- <td style="width: 180px;">{{ x.name }}</td>
- <td style="width: 180px;">{{ x.country }}</td>
- </tr>
- </table>
- </div>
- </form>
- </body>
- </html>
# using if condition in AngularJS With Even and Odd in a TableThe following is my external Controlller file.
- ngular.module('myApp', []).controller('employeeCtrl', 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' }
- ];
- });
- <%@ 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="employeeController.js"></script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div ng-app="myApp" ng-controller="employeeCtrl">
- <table style="border: 1px solid;" border="1">
- <tr ng-repeat="x in Emp_Names">
- <td ng-if="$odd" style="background-color: #1E90FF; width: 190px;">{{ x.name }}</td>
- <td ng-if="$even" style="background-color: #FF00FF; width: 190px;">{{ x.name }}</td>
- <td ng-if="$odd" style="background-color: #FF4500; width: 190px;">{{ x.country }}</td>
- <td ng-if="$even" style="background-color: #9ACD32; width: 190px;">{{ x.country }}</td>
- </tr>
- </table>
- </div>
- </form>
- </body>
- </html>
# Make disable button on ChecBox Click
- <%@ 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>
- </head>
- <body>
- <form id="form1" runat="server">
- <div ng-app="">
- <p>
- <button ng-disabled="mySwitchClick">Submit</button>
- </p>
- <p>
- <input type="checkbox" ng-model="mySwitchClick">Make Button Enable/Disable
- </p>
- </div>
- </form>
- </body>
- </html>