This blog shows you how an AngularJS application is run in VS Code with dummy data. Also, download the angular.min js file.

  • Download and install VS Code. Now, create a new application. The application looks as shown below.



  • Add a mainApp.js file to initialize the module and the query looks as shown below.
    1. var mainApp=angular.module("mainApp",[]);
  • Add another JS file of Controller and the query looks, as shown below.
    1. mainApp.controller("EmployeeController", function($scope) {
    2. $scope.employee = {
    3. firstnmae: "Jayant",
    4. lastName: "Tripathy",
    5. Age: 30,
    6. Technologies: [{
    7. Name: "Asp .Net",
    8. Exp: "5 years"
    9. }, {
    10. Name: "C#",
    11. Exp: "5 years"
    12. }, {
    13. Name: "Sql Server",
    14. Exp: "4 years"
    15. }, {
    16. Name: "Java",
    17. Exp: "0 years"
    18. }, {
    19. Name: "Jquery",
    20. Exp: "3 years"
    21. }],
    22. fullname: function() {
    23. var EmployeeObject;
    24. EmployeeObject = $scope.employee;
    25. return EmployeeObject.firstnmae + " " + EmployeeObject.lastName;
    26. }
    27. }
    28. });
  • Now, simply add a HTML file and add AngularJS cdn or you can download directly from angularjs.org site. HTML looks, as shown below.
    1. <html>
    2. <head>
    3. <script src="Script/angular.min.js"></script>
    4. <script src="Script/mainApp.js"></script>
    5. <script src="Script/EmployeeController.js"></script>
    6. <link href="Css/Style.css" rel="stylesheet" type="text/css" />
    7. <body>
    8. <div ng-app="mainApp" ng-controller="EmployeeController">
    9. <table>
    10. <tr>
    11. <td>FirstName :</td>
    12. <td><input type="text" ng-model="employee.firstnmae"> </td>
    13. </tr>
    14. <tr>
    15. <td>LastName :</td>
    16. <td><input type="text" ng-model="employee.lastName"> </td>
    17. </tr>
    18. <tr>
    19. <td>Age :</td>
    20. <td><input type="text" ng-model="employee.Age"> </td>
    21. </tr>
    22. <tr>
    23. <td>Name</td>
    24. <td>{{employee.fullname()| uppercase}}</td>
    25. </tr>
    26. </tr>
    27. <tr>
    28. <td>Technologies</td>
    29. <td>
    30. <table>
    31. <tr>
    32. <th>Subject</th>
    33. <th>Experience</th>
    34. </tr>
    35. <tr ng-repeat="emp in employee.Technologies">
    36. <td>{{emp.Name}}</td>
    37. <td>{{emp.Exp}}</td>
    38. </tr>
    39. </table>
    40. </td>
    41. </tr>
    42. </table>
    43. </body>
    44. </head>
    45. </html>
  • To style the table, I have added Css/Style.css.
    1. table, th , td {
    2. border: 1px solid grey;
    3. border-collapse: collapse;
    4. padding: 5px;
    5. }
    6. table tr:nth-child(odd) {
    7. background-color: #f2f2f2;
    8. }
    9. table tr:nth-child(even) {
    10. background-color: #ffffff;
    11. }
  • Finally, the result looks as shown below.