angularjs $http请求--图书
2017-10-16 07:48
232 查看
<!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.controller("bookCtrl", function ($scope, $http) { $http({ method: "GET", url: "book.json" }).success(function (data, status, headers, config) { $scope.book = data; }).error(function (data, status, headers, config) { console.log(status); }); }); app.controller("bookListCtrl", function ($scope, $http) { $http({ method: "GET", url: "books.json" }).success(function (data, status, headers, config) { $scope.books = data; }).error(function (data, status, headers, config) { console.log(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="bookListCtrl"> <table border="1"> <tr> <th>NO</th> <th>ID</th> <th>标题</th> <th>是否推荐</th> <th>价格</th> </tr> <tbody ng-repeat="book in books"> <tr> <td>{{$index}}</td> <td>{{book.id}}</td> <td>{{book.title}}</td> <td> <i ng-if="book.isRecommend">是</i> <i ng-if="!book.isRecommend">否</i> </td> <td>{{book.price}}</td> </tr> </tbody> </table> </div> </body> </html>
相关文章推荐
- 解决angularjs中同步执行http请求
- AngularJS中的$http缓存以及处理多个$http请求
- angularJS的http请求
- angularjs的http请求后台收不到数据
- 详解AngularJS中$http缓存以及处理多个$http请求的方法
- 在学习angularJS过程中关于使用$http请求与后台交互的问题
- 使用angularjs异步请求数据(http请求或者使用Websocket)的时候,更新$scope中的dom的方法
- AngularJs服务-http请求
- [置顶] 《AngularJS入门与进阶》图书简介
- 解决angularjs中同步执行http请求的方法
- angularJS --$http请求方式
- 详解AngularJS用Interceptors来统一处理HTTP请求和响应
- AngularJS基于http请求实现下载php生成的excel文件功能示例
- ionic中使用angularjs的http请求的坑
- AngularJS中的http请求默认为异步的,请问如何设置为同步请求呢?--使用$q
- angularJS- $http请求
- AngularJS如何跨域发起Http请求(Access-Control-Allow-Origin)
- 详解AngularJS中$http缓存以及处理多个$http请求的方法
- angularJs学习——图书列表(一):使用本地js文件数据源
- angularJs如何取消Http请求