using angularjs to read json file, but its not happening

This is not working for reading and inserting data, I have data.json in js folder

<ion-content>
  <div ng-controller="jsonCtrl" ng-repeat="d in data">
    <h2>{{d[0].name}}</h2>
    <h2>{{d[0].shortname}}</h2>
    <h2>{{d[0].reknown}}</h2>
    <p>{{d[0].bio}}</p>

      <h2>Total Data {{ getTotalData() }}</h2>

      <label>Name</label>
      <input type="text" ng-model="Name">

      <label>Short name</label>
      <input type="text" ng-model="Shortname">

      <label>Reknown</label>
      <input type="text" ng-model="Reknown">

      <label>Bio</label>
      <input type="text" ng-model="Bio">

      <button ng-click="addData()">Add</button>
  </div>
</ion-content>

app.js:

angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default 
    // (remove this to show the accessory bar above the keyboard for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

My controller looks like this:

.controller('jsonCtrl', function($scope, $http) {

  $http.get('data.json').success(function(res) {
    $scope.data = res;
    console.log($scope.data);
  });

  $scope.addData = function() {
    $scope.data.push({
      name: $scope.Name,
      shortname: $scope.Shortname,
      reknown: $scope.Reknown,
      bio: $scope.Bio
    });
  }

  $scope.getTotalData = function() {
    return $scope.data.length;
  }
});


Source: json

Leave a Reply