0

I'm trying to load data into my angular module from json file but instead of data i'm getting this.

   var app = angular.module('myApp', []);

app.controller("myCtrl",function($scope, $http)
 {
   $http.get('bookData.json').then(function(response){

      $scope.books = response.data;
    });
 });

And in my view displaying data as:

<body ng-controller="myCtrl">
     <div>{{"Book details"}}</div>
     <div>
       <table>
         <tr ng-repeat="x in books">
           <td>x.bookid</td>
           <td>x.author</td>
         </tr>
       </table>
     </div>
 <script data-require="[email protected]" src="https://code.angularjs.org/1.5.8/angular.js" data-semver="1.5.8"></script>
    <script src="app.js"></script>
  </body>
</html>

But i'm getting output as:

   Book details

x.bookid    x.author
x.bookid    x.author
x.bookid    x.author
x.bookid    x.author

https://plnkr.co/edit/ZqcnwOKZUdUo5eDIdjlh?p=preview

2 Answers 2

3

You need to wrap your logic with {{ and }} to make it recognisable by angular. Otherwise it'll print out as just plain text.

e.g

<td>{{x.bookid}}</td>
<td>{{x.author}}</td>
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah It works !! it was such a silly mistake. Thanku so much.
0
<body ng-controller="myCtrl">
    <div>
        <H1>Book details</H1>
    </div>
    <div>
        <table>
            <tr ng-repeat="x in books">
                <td>{{x.bookid}}</td>
                <td>{{x.author}}</td>
            </tr>
        </table>

Comments

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.