zoukankan      html  css  js  c++  java
  • AngularJs练习Demo9 Http

    @{
        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>
    

      

  • 相关阅读:
    《Android深入透析》之广播(Broadcast)
    曾经的程序员-《30岁的程序员,你迷惘了吗?》
    30岁的程序员,你迷惘了吗?
    Android: 详解触摸事件如何传递
    关于HTML5服务器发送事件(SSE)
    Android: 在onCreate()中获得对象尺寸
    jxl教程图文详解
    相当牛X的java版星际游戏
    程序员的无奈(十二):终于获得了投资
    图览各编程语言中敲击最多的键
  • 原文地址:https://www.cnblogs.com/sumg/p/5605354.html
Copyright © 2011-2022 走看看