我想从该URL获取书名

http://localhost:3000/greeting


这是我的nodejs Expressjs服务器代码

var express = require('express');
var app = express();

app.get('/greeting', function (req, res) {

var books = {
    id : 555,
    name : 'Antony',
    title : 'Do or Die',
    price : {
        inr : 500,
        dollar : 5
        }
    };
    res.json(books);
});

app.listen(3000, function () {
console.log('Example app listening on port 3000!')
});


这段代码是我的Angularjs网络服务调用,名为hello.js

var app = angular.module('booksInventoryApp', []);
app.controller('booksCtrl', function($scope, $http) {
$http.get("http://localhost:3000/greeting")
   .then(function(response) {
  $scope.data = response.data;
  console.log("result"+response.data);
  });
});


这是我的HTML代码

<!doctype html>
<html ng-app="demo">
<head>
    <title>Hello AngularJS</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <script src="hello.js"></script>
</head>

<body>

<article ng-app="booksInventoryApp">
    <section ng-controller="booksCtrl">
        <h2 ng-repeat="book in data.books">{{book.name}}</h2>
    </section>
</article>




</body>
</html>


我想获取书名...在此先谢谢..

最佳答案

您的主要app名称是booksInventoryApp,因此您应该包括ng-app="booksInventoryApp",并且每个页面都有一个ng-app指令。

所以尝试改变

 ng-app="demo"




 ng-app="booksInventoryApp"


并从ng-app="booksInventoryApp"删除<article ng-app="booksInventoryApp">

关于javascript - AngularJs Web服务,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44342653/

10-11 09:20