首页 > Web开发 > 详细

angularjs--resource

时间:2017-07-26 21:19:18      阅读:206      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>无标题文档</title>
        <script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.min.js"></script>
        <script src="http://cdn.bootcss.com/angular.js/1.3.8/angular-resource.min.js"></script>
    </head>
    <body>
      <div ng-app="myApp">
          <div ng-controller="firstController">
           {{name}}
           {{data.name}}
          </div>
      </div>
      <script type="text/javascript">
          var app = angular.module(myApp,[ngResource]);
          app.controller(firstController,[$scope,$resource,function($scope,$resource){
              var obj = $resource(lisi.json);
          $scope.data1 = obj.get();
              $scope.data = obj.get({name:zhangsan},function(data){//请求zhangsan.json
                  console.log(data);
                  console.log(data.name);
              },function(error){
                  console.log(error);
              });
              console.log($scope.data);
              $scope.name = 张三;
          }]);
      </script>
    </body>
</html>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>无标题文档</title>
        <script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.min.js"></script>
        <script src="http://cdn.bootcss.com/angular.js/1.3.8/angular-resource.min.js"></script>
    </head>
    <body>
      <div ng-app="myApp">
          <div ng-controller="firstController">
           {{name}}
           {{data.name}}
          </div>
      </div>
      <script type="text/javascript">
          var app = angular.module(myApp,[ngResource]);
          app.controller(firstController,[$scope,$resource,function($scope,$resource){
              var obj=$resource(:name.:type);
            //  $scope.data=obj.get();
              $scope.data=obj.get({name:lisi,type:json},function(data){//请求lisi.json
                  console.log(data.name);
              },function(error){
                  console.log(error);
              });
            console.log($scope.data);
              $scope.name = 张三;
          }]);
      </script>
    </body>
</html>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>无标题文档</title>
        <script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.min.js"></script>
        <script src="http://cdn.bootcss.com/angular.js/1.3.8/angular-resource.min.js"></script>
    </head>
    <body>
      <div ng-app="myApp">
          <div ng-controller="firstController">
           {{name}}
           {{data.name}}
             <ul>
                 <li ng-repeat="d in data">
                     {{d.name}}--{{d.age}}
                 </li>
             </ul>
          </div>
      </div>
      <script type="text/javascript">
          var app = angular.module(myApp,[ngResource]);
          app.controller(firstController,[$scope,$resource,function($scope,$resource){
              var obj=$resource(:name.:type);
            //  $scope.data=obj.get();
              $scope.data=obj.query({name:zhangsan,type:json});
             console.log($scope.data);
              $scope.name = 张三;
          }]);
      </script>
    </body>
</html>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>无标题文档</title>
        <script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.min.js"></script>
        <script src="http://cdn.bootcss.com/angular.js/1.3.8/angular-resource.min.js"></script>
    </head>
    <body>
      <div ng-app="myApp">
          <div ng-controller="firstController">
           {{name}}
           {{data.name}}
             <ul>
                 <li ng-repeat="d in data">
                     {{d.name}}--{{d.age}}
                 </li>
             </ul>
          </div>
      </div>
      <script type="text/javascript">
          var app = angular.module(myApp,[ngResource]);
          app.controller(firstController,[$scope,$resource,function($scope,$resource){
              var obj=$resource(:name.:type,{type:json});
            //  $scope.data=obj.get();
              $scope.data=obj.query({name:zhangsan});
             console.log($scope.data);
              $scope.name = 张三;
          }]);
      </script>
    </body>
</html>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>无标题文档</title>
        <script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.min.js"></script>
        <script src="http://cdn.bootcss.com/angular.js/1.3.8/angular-resource.min.js"></script>
    </head>
    <body>
      <div ng-app="myApp">
          <div ng-controller="firstController">
           {{name}}
           {{data.name}}
             <ul>
                 <li ng-repeat="d in data">
                     {{d.name}}--{{d.age}}
                 </li>
             </ul>
          </div>
      </div>
      <script type="text/javascript">
          var app = angular.module(myApp,[ngResource]);
          app.controller(firstController,[$scope,$resource,function($scope,$resource){
              //var obj=$resource(‘:name.:type‘,{type:‘json‘});
              var obj = $resource(http://www.57lehuo.com/json.php,
                      {id:@id},{getAge: {method: GET, params: {age:40},isArray: false},
                          getSex: {method: GET, params: {sex:nv,age:32},isArray: false}});
              $scope.data=obj.get({id:20});
              $scope.data2=obj.getAge({id:21});
              $scope.data3=obj.getSex({id:21});
              //$scope.data=obj.query({name:‘zhangsan‘});
              console.log($scope.data);
              console.log($scope.data2);
              console.log($scope.data3);
              $scope.name = 张三;
          }]);
      </script>
    </body>
</html>

 

angularjs--resource

原文:http://www.cnblogs.com/yaowen/p/7241704.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!