angularjs--resource

Posted 672530440

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了angularjs--resource相关的知识,希望对你有一定的参考价值。

<!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的主要内容,如果未能解决你的问题,请参考以下文章

AngularJS $resource GET 中的多个参数

了解 angularJS $resource isArray 属性

angularjs $resource 和一对多关系

angularjs $resource 类级回调,或后处理

使用 ANGULARJS $resource 发布一个 JSON 数组

AngularJS $resource 不发送 X-Requested-With