无法打印带有angularjs,HTML和REST的表格

Can't print table with angularjs, HTML and REST

本文关键字:HTML REST 表格 angularjs 打印      更新时间:2023-09-26

我对问题中提到的技术很陌生。尝试使用它们生成表。目前,我可以从浏览器中获取表格的json格式,但即使在控制台(.js文件中)也无法打印。这里的原因是什么?

HTML

<!doctype html>
<html data-ng-app>
<head>
<title>Book</title>
 <script src="index.js"></script>
 </head>
  <body background="/images/library-wall.jpg">
    <center>
   <div data-ng-app="bookApp">
    <div data-ng-controller="bookListCtrl">
        <table border = "1">
            <tr>
                <th>#</th>
                <th color = "#0000FF">Title</th>
                <th>Author</th>
                <th>ISBN</th>
                <th>Brief Description</th>
                <th>Location</th>
            </tr>
            <tr data-ng-repeat="book in books">
                <td>{{book.id}}</td>
                <td>{{book.title}}</td>
                <td>{{book.author}}</td>
                <td>{{book.isbn}}</td>
                <td>{{book.description}}</td>
                <td>{{book.location}}</td>
            </tr>
        </table>
    </div>
</div>

JS:

var booksApp = angular.module('booksApp', []);
books.controller('bookListCtrl', function($scope, $http) {  
$http.get('books').success(function(data) {
    console.log(data);
    $scope.books = data;
});
});

休息

@RequestMapping(value = "/books", method = RequestMethod.GET)
ResponseEntity<Collection<Book>> allOffices() {
    return new ResponseEntity<Collection<Book>>(bookRepository.findAll(),
            HttpStatus.OK);
}

每个 HTML 只能自动引导一个 AngularJS 应用程序 公文。在文档中找到的第一个 ngApp 将用于定义 要作为应用程序自动引导的根元素。运行多个 HTML 文档中的应用程序,您必须手动引导它们 改用 angular.bootstrap。AngularJS 应用程序不能 相互嵌套。

http://docs.angularjs.org/api/ng.directive:ngApp

尝试:

<!doctype html>
<html>
<head>
<title>Book</title>
 <script src="index.js"></script>
 </head>
  <body background="/images/library-wall.jpg">
    <center>
   <div data-ng-app="bookApp">
    <div data-ng-controller="bookListCtrl">
        <table border = "1">
            <tr>
                <th>#</th>
                <th color = "#0000FF">Title</th>
                <th>Author</th>
                <th>ISBN</th>
                <th>Brief Description</th>
                <th>Location</th>
            </tr>
            <tr data-ng-repeat="book in books">
                <td>{{book.id}}</td>
                <td>{{book.title}}</td>
                <td>{{book.author}}</td>
                <td>{{book.isbn}}</td>
                <td>{{book.description}}</td>
                <td>{{book.location}}</td>
            </tr>
        </table>
    </div>
</div>
var booksApp = angular.module('booksApp', []);
books.controller('

不应该是书本吧?

如何检查我的 Web 服务和网页是否正在运行:

首先,使用 Postman 通过 GET 方法向 Web 服务发送请求。如果收到响应,则表示成功。

其次,查找angularjs文档找到您的错误。假设您的 Web 服务的主机是 http://127.0.0.1:5000 ,请将url设置为 http://127.0.0.1:5000/books

请确保客户端和服务器端能够工作。