angularjs获取json解析(http)

来源:互联网 发布:使用python ddos攻击 编辑:程序博客网 时间:2024/05/18 15:50
<!DOCTYPE html><html><head>    <meta charset="UTF-8">    <script type="text/javascript" src="angular-1.3.0.js"></script>    <title></title>    <script type="text/javascript">        var app = angular.module("myApp", []);        app.value("url_book", "book.json");        app.value("url_books", "books.json");        app.controller("bookCtrl", function ($scope, $http) {            $http.get("book.json").then(function (response) {                $scope.book = response.data;            }, function (response) {                console.log(response.status);            });        });        app.controller("booksCtrl", function ($scope, $http) {            $http.get("books.json").then(function (response) {                $scope.books = response.data;            }, function (response) {                console.log(response.status);            });        });    </script></head><body ng-app="myApp"><div ng-controller="bookCtrl">    <ul>        <li>ID:{{ book.id }}</li>        <li>标题:{{ book.title }}</li>        <li>类型:{{ book.type }}</li>        <li>描述:{{ book.description }}</li>        <li>图片:<img src="{{ book.picture }}"/></li>        <li>是否推荐:{{ book.isRecommend }}</li>        <li>上架时间:{{ book.dtCreated }}</li>    </ul></div><div ng-controller="booksCtrl">    <table border="1">        <tr>            <th>ID</th>            <th>标题</th>            <th>类型</th>            <th>描述</th>            <th>图片</th>            <th>推荐</th>            <th>创建时间</th>        </tr>        <tbody ng-repeat="book in books">        <tr>            <td>{{book.id}}</td>            <td>{{book.title}}</td>            <td>{{book.type}}</td>            <td>{{book.description}}</td>            <td>                <img src="{{book.picture}}" width="80px" height="80px"/>            </td>            <td>                <i ng-if="book.isRecommend"></i>                <i ng-if="!book.isRecommend"></i>            </td>            <td>{{book.dtCreated}}</td>        </tr>        </tbody>    </table></div></body></html>
原创粉丝点击