Import JSON File Using AngularJS
Submitted by razormist on Thursday, August 13, 2020 - 20:50.
In this tutorial we will create Import JSON File using AngularJS. The program will upload and display the json object as a readable text format. Feel free to use this code and modify as you learn from it. To learn more about this, just follow the steps below.
data.json
Getting started:
First you will need to download & install the AngularJS here's the link https://angularjs.org/. And this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/. Note: This code will only work if run in a local server.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.- <!DOCTYPE html>
- <html lang="en" ng-app="myModule">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body ng-controller="myController">
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- </div>
- </nav>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-3">
- </div>
- <div class="col-md-6">
- <table class="table table-bordered">
- <thead class="alert-info">
- <tr>
- </tr>
- </thead>
- <tbody style="background-color:#fff;">
- <tr ng-repeat="member in members | orderBy: 'lastname'">
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- </body>
- </html>
- </html>
Creating the Main Function
This code contains the main function of the application. The code will dynamically display the json data when import. To that just kindly copy and write these block of codes inside the text editor, then save it inside the js folder as shown below. script.js- var app = angular.module("myModule", [])
- .controller("myController", function($scope){
- $scope.members = [
- {name: "John Smith", age: "21"},
- {name: "Claire Temple", age: "18"}
- ];
- $scope.members2 = [];
- $scope.transfer = function(member){
- $scope.members2.push(member);
- $scope.members.splice($scope.members.indexOf(member), 1);
- };
- });
[
{"firstname": "John", "lastname": "Smith", "address": "New York"},
{"firstname": "Claire", "lastname": "Temple", "address": "Racoon City"}
]
There you have it we successfully created a Import JSON File 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!!Add new comment
- 397 views