AngularJs练习Demo9 Http
2016-06-21 23:03
417 查看
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Provider</title> <script type="text/javascript" src="~/Scripts/angular.js"></script> <script type="text/javascript"> var myApp = angular.module("myApp", []); // myApp.service("serviceServices01", function ($http, $log) {//不能直接返回字符串,因为内部是用new来实例化的所以可以直接用this来表示当前的service //var _name = ""; //var service = {}; //service.setName = function (name) { // _name = name; //} //service.getName = function (name) { // return _name; //} //return service; // $log.warn("警告"); var _name = ""; var service = {}; this.setName = function (name) { _name = name; }; this.getName = function (name) { return _name; }; this.getData = function () { var myUrl = "http://wwww.phonegap100.com/apiapi.php?a=getPortallList&catid=20&page=1&callback=JSON_CALLBACK"; return $http.jsonp(myUrl, { cache: true });//缓存请求,相同的请求直接从缓存取数据不会再跑服务器 // return _name; } }); myApp.controller("firstController", ["$scope", "serviceServices01", "$location", function ($scope, serviceServices01, $location) { $scope.name = "张三"; console.log($location.absUrl()); serviceServices01.getData().success(function (data) { console.log(data); }).error(function (err) { console.log("失败"); }); }]); myApp.controller("secondController", ["$scope", "serviceServices01", function ($scope, serviceServices01) { $scope.name = "李四"; }]); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="firstController"> {{name}} </div> <div ng-controller="secondController"> {{name}} </div> </div> </body> </html>
相关文章推荐
- 利用FastJson来解析网络数据
- HTTP协议/RTSP协议/RTMP协议的区别
- HTTP与HTTPS的区别
- tcp总结
- linux网络编程-----实现并发访问网站------
- 使用HOG特征+BP神经网络进行车标识别
- 网络编程常见类型定义
- TCP/IP协议
- 【网络编程5】Java与Python套接字Socket通信的例子
- C#检测本地网络状态
- 详解https是如何确保安全的?
- 使用Http-only Cookie来防止XSS攻击
- HTTP学习笔记——报文格式
- TCP三次握手(建立连接)/四次挥手(关闭连接)
- 深入理解nginx chap3 开发一个简单的HTTP模块
- OkHttp使用(二)加载图片及下载文件
- OkHttp使用(一)基本使用
- 网络地址转换相关函数使用(inet_addr,inet_ntoa,inet_addr)
- java https post(不带证书的)
- 【转】asp.net(c#)使用HttpWebRequest附加携带请求参数以post方式模拟上传大文件(以图片为例)到Web服务器端