0

I am looking at this tutorial. And I have such code:

<!DOCTYPE html>
<html lang="en" ng-app="">
<head>
    <meta charset="UTF-8">
    <title>SPA book_store</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope, $http) {
        $http.get("http://localhost:8080/book_store/rest/books_json/get")
                .then(function(response) {
                    $scope.books = response.data;
                });
    });
</script>

<div ng-app="myApp" ng-controller="myCtrl">
<input id="filter_input" type="text" ng-model="nameText"/>
<ul>
    <li ng-repeat="book in books | filter:nameText | orderBy:'name'">
        {{book.name}} - {{book.price}}
    </li>
</ul>
</div>

</body>
</html>  

http://localhost:8080/book_store/rest/books_json/get is returning following json:

[  
   {  
      "book_id":1,
      "name":"Book1",
      "bought":false,
      "genre":"MR",
      "price":20,
      "users":[  

      ],
      "author":{  
         "author_id":1,
         "name":"Gogol",
         "books":[  

         ]
      }
   },
//...
]

But I see in a browser networking that request wasn't fire. What have I done wrong?

8
  • So you mean in your network tab there isn't any request to http://localhost:8080/book_store/rest/books_json/get ? Or doesn't it return anything? Or doesn't it display anything? Commented Aug 4, 2016 at 10:32
  • Check your console tab in developer tools of your browser, there must be some error. Commented Aug 4, 2016 at 10:33
  • @devqon, yes, I mean exactly this Commented Aug 4, 2016 at 10:33
  • Copied and pasted your code in this jsfiddle, and it does the request Commented Aug 4, 2016 at 10:35
  • I have exception in the browser console: angular.js:13920Error: [ng:areq] http://errors.angularjs.org/1.5.8/ng/areq?p0=myCtrl&p1=not%20a%20function%2C%20got%20undefined Commented Aug 4, 2016 at 10:39

1 Answer 1

1

Remove the ng-app="" from the html tag or provide the module name ng-app="MyApp".

Also remove one of the ng-app directives either from the the body tag or the html tag.

It is good practice to user the ng-app directive on the HTML tag if you are using just one angular app.

Sign up to request clarification or add additional context in comments.

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.