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>
    

      

  • 相关阅读:
    http://localhost:8080/ 演出Oracle说明
    JS浏览器类型推断方法
    MVC设计模式JavaWeb实现
    《TCP/IP详细说明》读书笔记(17章)-TCP传输控制协定
    创建表单
    道路软件质量:SourceMonitor
    HDU
    HDU 3032 Nim or not Nim? (sg函数求解)
    OpenWRT推理client线上的数
    IIS的ISAPI接口简介
  • 原文地址:https://www.cnblogs.com/sumg/p/5605354.html
Copyright © 2011-2022 走看看