• We just launched and are currently in beta. Join us as we build and grow the community.

Display Array Object Using AngularJS

ItsZuen

Social Outreach Coordinator
I Rep
0
0
0
Rep
0
I Vouches
0
0
0
Vouches
0
Posts
89
Likes
70
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
This simple code will show you how to do Display Array Object using AngularJS. The code will dynamically populate the HTML table by an array object. With the use of AngularJS plugin it is easier to manipulate with arrays. To learn more about this, just follow the steps below.

Getting started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.

And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

Lastly, you will need to download the AngularJS here's the link https://angularjs.org/.

Creating the Main Interface

This code contains the interface of the application. This code will render application and display the form. To do that just kindly write these block of code inside the text editor and save this as index.html.
  1. <!DOCTYPE html>
  2. <html

    lang

    =

    "en"

    ng-app =

    "myModule"

    >
  3. <head

    >
  4. <meta

    charset

    =

    "UTF-8"

    name

    =

    "viewport"

    content

    =

    "width=device-width, initial-scale=1"

    /

    >
  5. <link

    rel

    =

    "stylesheet"

    type

    =

    "text/css"

    href

    =

    "css/bootstrap.css"

    /

    >
  6. </

    head

    >
  7. <body

    ng-controller=

    "myController"

    >
  8. <nav class

    =

    "navbar navbar-default"

    >
  9. <div

    class

    =

    "containet-fluid"

    >
  10. <a

    class

    =

    "navbar-brand"

    href

    =

    "https://www.sourcecodester.com"

    >

    Sourcecodester</

    a

    >
  11. </

    div

    >
  12. </

    nav>
  13. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  14. <div

    class

    =

    "col-md-6 well"

    >
  15. <h3

    class

    =

    "text-primary"

    >

    Display Array Object Using AngularJS</

    h3

    >
  16. <hr

    style

    =

    "border-top:1px dotted #ccc;"

    /

    >
  17. <div

    class

    =

    "container-fluid"

    >
  18. <button

    ng-click=

    "getArray();"

    class

    =

    "btn btn-primary"

    >

    Display Array</

    button

    >
  19. <br

    /

    ><br

    /

    >
  20. <table

    class

    =

    "table table-bordered"

    >
  21. <thead

    class

    =

    "alert-info"

    >
  22. <tr

    >
  23. <th

    >

    Member ID</

    th

    >
  24. <th

    >

    Firstname</

    th

    >
  25. <th

    >

    Lastname</

    th

    >
  26. <th

    >

    Grade</

    th

    >
  27. </

    tr

    >
  28. </

    thead

    >
  29. <tbody

    >
  30. <tr

    ng-repeat =

    "student in students"

    >
  31. <td

    >

    {{$index+1}}</

    td

    >
  32. <td

    >

    {{student.firstname}}</

    td

    >
  33. <td

    >

    {{student.lastname}}</

    td

    >
  34. <td

    >

    {{student.address}}</

    td

    >
  35. </

    tr

    >
  36. </

    tbody

    >
  37. </

    table

    >
  38. </

    div

    >
  39. </

    div

    >
  40. </

    body

    >
  41. <script

    src

    =

    "js/jquery-3.2.1.min.js"

    ></

    script

    >
  42. <script

    src

    =

    "js/angular.js"

    ></

    script

    >
  43. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  44. <script

    src

    =

    "js/bootstrap.js"

    ></

    script

    >
  45. </

    html

    >

Creating the Main Function

This code contains the main function of the application. This code will display a list of an array object. To that just kindly copy and write these block of codes inside the text editor, then save it as shown below.
  1. var

    app =

    angular.module

    (

    "myModule"

    ,

    [

    ]

    )
  2. .controller

    (

    "myController"

    ,

    function

    (

    $scope)

    {

  3. $scope.arrays

    =

    [
  4. {

    firstname:

    "John"

    ,

    lastname:

    "Smith"

    ,

    address:

    "New York"

    }

    ,
  5. {

    firstname:

    "Claire"

    ,

    lastname:

    "Temple"

    ,

    address:

    "Racoon City"

    }

    ,
  6. {

    firstname:

    "John"

    ,

    lastname:

    "Wick"

    ,

    address:

    "Pearl Harbor"

    }

    ,
  7. ]

    ;

  8. $scope.getArray

    =

    function

    (

    )

    {
  9. $scope.students

    =

    $scope.arrays

    ;
  10. }
  11. }

    )

    ;

There you have it we successfully created a Display Array Object using AngularJS. I hope that this very simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!


Download
You must upgrade your account or reply in the thread to view hidden text.
 

442,401

317,942

317,951

Top