2

I am new to ionic and angular. was trying to create a list with json data

{"menu":[{"name":"Mixed Veg Wrap","image":"mix-veg-wrap.jpg","category":"WRAPS, Light Bites","spice_meter":"1","description":"Spicy mixed vegetables :)","rating":"3","price":"35","is_veg":"yes"},{"name":"Egg Wrap","image":"egg-wraps.jpg","category":"WRAPS, Light Bites","spice_meter":"0","description":"Double egg coating with Onion and Sauces!","rating":"4.9","price":"36","is_veg":"no"},{"name":"Cheese Melt Paneer","image":"cmp.jpg","category":"WRAPS, Special","spice_meter":"0","description":"Paneer in Reshmi Masala with melted Cheese","rating":"4.5","price":"91","is_veg":"yes"},{"name":"Prawns Tikka","image":"prawan.jpg","category":"WRAPS, Special","spice_meter":"1","description":"Prawns in spicy tikka masala.","rating":"3.5","price":"110","is_veg":"no"}

Here is my controller the app.js

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
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();
    }
  });
}).controller('ListController', ['$scope', '$http', function($scope, $http) {
    $http.get('js/data.json').success(function(data) {
      $scope.menu = data;  
    });
}]);

Here is my index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
  </head>
  <body ng-app="starter">
    <ion-pane>
      <ion-header-bar class="bar-dark">
        <h2 class="title">Artist List</h2>
      </ion-header-bar>
      <div class="bar bar-subheader 
        item-input-inset bar-light">
        <label class="item-input-wrapper">
          <i class="icon ion-search placeholder-icon"></i>
          <input type="search" placeholder="Search">
        </label>
      </div>
      <ion-content ng-controller="ListController" 
        class="has-subheader">
        <ion-list>
          <ion-item ng-repeat='item in menu'
          class="item-text-wrap">
          <h2>{{item.name}}</h2>
            <img ng-src="img/{{item.image}}" />
            <h3>{{item.category}}</h3>
            <h3>{{item.spice_meter}}</h3>
            <h3>{{item.description}}</h3>
            <h3>{{item.rating}}</h3>
            <h3>{{item.price}}</h3>
            <h3>{{item.is_veg}}</h3>
          </ion-item>
        </ion-list>
      </ion-content>
    </ion-pane>
  </body>
</html>

Nut the resultant o/p is blank list i checked the console which shows

ionic.bundle.js:17752 XHR finished loading: GET "http://192.168.1.201:8100/js/data.json".(anonymous function) @ ionic.bundle.js:17752sendReq @ ionic.bundle.js:17553serverRequest @ ionic.bundle.js:17269processQueue @ ionic.bundle.js:21114(anonymous function) @ ionic.bundle.js:21130Scope.$eval @ ionic.bundle.js:22326Scope.$digest @ ionic.bundle.js:22142Scope.$apply @ ionic.bundle.js:22431bootstrapApply @ ionic.bundle.js:9373invoke @ ionic.bundle.js:12110doBootstrap @ ionic.bundle.js:9371bootstrap @ ionic.bundle.js:9391angularInit @ ionic.bundle.js:9285(anonymous function) @ ionic.bundle.js:34050trigger @ ionic.bundle.js:10669eventHandler @ ionic.bundle.js:10939

Please help!!

1 Answer 1

1

Make sure that the path you are seeing in browser console http://192.168.1.201:8100/js/data.json is correct.

Then while assigning menu use data.menu instead of just data

.controller('ListController', ['$scope', '$http', function($scope, $http) {
    $http.get('js/data.json').success(function(data) {
      $scope.menu = data.menu;  //assigning menu
    });
}]);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank u some much.. for quick help.. really helped!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.