This is the continuation from AngularJS Recipe: Part 3.

# ng-show Directive

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AngularJS_Demo.Default" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title></title>
  6. <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
  7. <script src="employeeController.js"></script>
  8. </head>
  9. <body>
  10. <form id="form1" runat="server">
  11. <div ng-app="">
  12. <p ng-show="true">I Can Show</p>
  13. <p ng-show="false">Oops.. I am hide.</p>
  14. <p ng-hide="true">Not Visible.</p>
  15. <p ng-hide="false">I am Visible.</p>
  16. </div>
  17. </form>
  18. </body>
  19. </html>


# Button and click event in AngularJS
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AngularJS_Demo.Default" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title></title>
  6. <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
  7. <script>
  8. var app = angular.module('myApp', []);
  9. app.controller('myCtrl', function ($scope) {
  10. $scope.count = 0;
  11. });
  12. </script>
  13. </head>
  14. <body>
  15. <div ng-app="myApp" ng-controller="myCtrl">
  16. <button ng-click="count = count + 1">Count Me!</button>
  17. <p>Your Total Count: {{ count }}</p>
  18. </div>
  19. </body>
  20. </html>




# Another Example Of Button Click in AngularJS
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AngularJS_Demo.Default" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title></title>
  6. <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
  7. <script>
  8. var app = angular.module('myApp', []);
  9. app.controller('empCtrl', function ($scope) {
  10. $scope.Name = "Rahul Saxena",
  11. $scope.address = "Noida, India"
  12. $scope.myVar = false;
  13. $scope.GetAllInfo = function () {
  14. $scope.FullName = $scope.Name + " " + $scope.address;
  15. }
  16. });
  17. </script>
  18. </head>
  19. <body>
  20. <div ng-app="myApp" ng-controller="empCtrl">
  21. <p>
  22. Name:
  23. <input type="text" ng-model="Name"><br />
  24. <br />
  25. Address:
  26. <input type="text" ng-model="address"><br />
  27. <br>
  28. <button ng-click="GetAllInfo()">Get Info</button>
  29. <br />
  30. <br />
  31. Employee Information : {{FullName}}
  32. </p>
  33. </div>
  34. </body>
  35. </html>


# Show Hide on button Click in AngularJS

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AngularJS_Demo.Default" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title></title>
  6. <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
  7. <script>
  8. var app = angular.module('myApp', []);
  9. app.controller('empCtrl', function ($scope) {
  10. $scope.Name = "Rahul Saxena",
  11. $scope.address = "Noida, India"
  12. $scope.myVar = true;
  13. $scope.toggle = function () {
  14. $scope.myVar = !$scope.myVar;
  15. }
  16. });
  17. </script>
  18. </head>
  19. <body>
  20. <div ng-app="myApp" ng-controller="empCtrl">
  21. <p ng-show="myVar">
  22. Name:
  23. <input type="text" ng-model="Name"><br />
  24. <br />
  25. Address:
  26. <input type="text" ng-model="address"><br />
  27. </p>
  28. <p>
  29. <button ng-click="toggle()">Toggle</button>
  30. </p>
  31. </div>
  32. </body>
  33. </html>