Thank you for reading my previous articles. If you have not read them, then study from the following links. After reading them it will be easier to understand today’s topics.

Routing in AngularJS

It helps us to divide your app into multiple view and bind it different views to Controllers. A route is specified in the URL after the # sign.

Like:

$ rout Provider taken care by AngularJS. To define the routes for your app$route Provider service provides method when () and otherwise ().

Example:

  1. var sampleApp = angular.module('sampleApp', []);
  2. sampleApp.config(['$routeProvider',
  3. function($routeProvider)
  4. {
  5. $routeProvider.
  6. when('/ShowOrder/:orderId',
  7. {
  8. templateUrl: 'templates/show_order.html',
  9. controller: 'ShowOrderController'
  10. });
  11. }
  12. ]);
  13. sampleApp.controller('ShowOrderController', function($scope, $routeParams)
  14. {
  15. $scope.order_id = $routeParams.orderId;
  16. });
AngularJS Events

That directive allows you to run its functions at user event. It is not overwriting with HTML5 event. In page both events can be executed at a time.

It has several types:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Event Demo</title>
  5. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
  6. </script>
  7. </head>
  8. <body>
  9. <h3> Angular JS change Events</h3>
  10. <br/>
  11. <script>
  12. var app = angular.module("app", []);
  13. app.controller("ChangeController", function($scope)
  14. {
  15. $scope.CheckBoxChanged = function()
  16. {
  17. $scope.CheckBoxStatus = $scope.chkValue;
  18. };
  19. $scope.KeyDown = function()
  20. {
  21. $scope.keydown = " Key down executes " + new Date().getTime();
  22. }
  23. $scope.TextBoxChanged = function()
  24. {
  25. $scope.TextBoxStatus = $scope.txtValue;
  26. };
  27. $scope.KeyPress = function()
  28. {
  29. $scope.keypress = " Key press executes " + new Date().getTime();
  30. }
  31. $scope.DropDownChnaged = function()
  32. {
  33. $scope.DropDownStatus = $scope.dropValue;
  34. };
  35. });
  36. </script>
  37. <div ng-app="app" ng-controller="ChangeController">
  38. <input type="checkbox" name="chk1" ng-model="chkValue" ng-change="CheckBoxChanged()" />
  39. <p>Check box status: {{ CheckBoxStatus }}</p>
  40. <br/>
  41. <inputtype="text" name="txt1" ng-model="txtValue" ng-change="TextBoxChanged()" />
  42. <p>Text box status: {{ TextBoxStatus }}</p>
  43. <input type="text" ng-keydown="KeyDown()" ng-keypress="KeyPress()" ng-keyup="KeyUp()" />
  44. <br/>
  45. <p>Key down - {{ keydown }}</p>
  46. <p>Key press - {{ keypress }}</p>
  47. <br/>
  48. <select name="dropChange" ng-model="dropValue" ng-change="DropDownChnaged()">
  49. <option value="Male">Male</option>
  50. <option value="Female">Female</option>
  51. </select>
  52. <p>Dropdown box status: {{ DropDownStatus }}</p>
  53. </div>
  54. </body>
  55. </html>
  56. <!DOCTYPE html>
  57. <html>
Output

output

I hope you will understand and will practice with my demo.