diff options
| author | Misko Hevery | 2012-04-28 22:45:28 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2012-05-04 16:12:17 -0700 | 
| commit | 8e2675029f5ca404a7c649cc161df3ea642d941f (patch) | |
| tree | 6668342fb2c57360e06c9e36bfd4e5e6e08a52f5 /src/ng/http.js | |
| parent | d0159454dfa2e1cee4dd4ab7a41c2fcf9e121a64 (diff) | |
| download | angular.js-8e2675029f5ca404a7c649cc161df3ea642d941f.tar.bz2 | |
chore(docs): re-skin main documentation
Diffstat (limited to 'src/ng/http.js')
| -rw-r--r-- | src/ng/http.js | 135 | 
1 files changed, 69 insertions, 66 deletions
| diff --git a/src/ng/http.js b/src/ng/http.js index 157c5d98..19b7d246 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -400,72 +400,75 @@ function $HttpProvider() {       *       *       * @example -        <doc:example> -          <doc:source jsfiddle="false"> -            <script> -              function FetchCtrl($scope, $http) { -                $scope.method = 'GET'; -                $scope.url = 'examples/http-hello.html'; - -                $scope.fetch = function() { -                  $scope.code = null; -                  $scope.response = null; - -                  $http({method: $scope.method, url: $scope.url}). -                    success(function(data, status) { -                      $scope.status = status; -                      $scope.data = data; -                    }). -                    error(function(data, status) { -                      $scope.data = data || "Request failed"; -                      $scope.status = status; -                  }); -                }; - -                $scope.updateModel = function(method, url) { -                  $scope.method = method; -                  $scope.url = url; -                }; -              } -            </script> -            <div ng-controller="FetchCtrl"> -              <select ng-model="method"> -                <option>GET</option> -                <option>JSONP</option> -              </select> -              <input type="text" ng-model="url" size="80"/> -              <button ng-click="fetch()">fetch</button><br> -              <button ng-click="updateModel('GET', 'examples/http-hello.html')">Sample GET</button> -              <button ng-click="updateModel('JSONP', 'http://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero')">Sample JSONP</button> -              <button ng-click="updateModel('JSONP', 'http://angularjs.org/doesntexist&callback=JSON_CALLBACK')">Invalid JSONP</button> -              <pre>http status code: {{status}}</pre> -              <pre>http response data: {{data}}</pre> -            </div> -          </doc:source> -          <doc:scenario> -            it('should make an xhr GET request', function() { -              element(':button:contains("Sample GET")').click(); -              element(':button:contains("fetch")').click(); -              expect(binding('status')).toBe('200'); -              expect(binding('data')).toBe('Hello, $http!\n'); -            }); - -            it('should make a JSONP request to angularjs.org', function() { -              element(':button:contains("Sample JSONP")').click(); -              element(':button:contains("fetch")').click(); -              expect(binding('status')).toBe('200'); -              expect(binding('data')).toMatch(/Super Hero!/); -            }); - -            it('should make JSONP request to invalid URL and invoke the error handler', -                function() { -              element(':button:contains("Invalid JSONP")').click(); -              element(':button:contains("fetch")').click(); -              expect(binding('status')).toBe('0'); -              expect(binding('data')).toBe('Request failed'); -            }); -          </doc:scenario> -        </doc:example> +      <example> +        <file name="index.html"> +          <div ng-controller="FetchCtrl"> +            <select ng-model="method"> +              <option>GET</option> +              <option>JSONP</option> +            </select> +            <input type="text" ng-model="url" size="80"/> +            <button ng-click="fetch()">fetch</button><br> +            <button ng-click="updateModel('GET', 'http-hello.html')">Sample GET</button> +            <button ng-click="updateModel('JSONP', 'http://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero')">Sample JSONP</button> +            <button ng-click="updateModel('JSONP', 'http://angularjs.org/doesntexist&callback=JSON_CALLBACK')">Invalid JSONP</button> +            <pre>http status code: {{status}}</pre> +            <pre>http response data: {{data}}</pre> +          </div> +        </file> +        <file name="script.js"> +          function FetchCtrl($scope, $http, $templateCache) { +            $scope.method = 'GET'; +            $scope.url = 'http-hello.html'; + +            $scope.fetch = function() { +              $scope.code = null; +              $scope.response = null; + +              $http({method: $scope.method, url: $scope.url, cache: $templateCache}). +                success(function(data, status) { +                  $scope.status = status; +                  $scope.data = data; +                }). +                error(function(data, status) { +                  $scope.data = data || "Request failed"; +                  $scope.status = status; +              }); +            }; + +            $scope.updateModel = function(method, url) { +              $scope.method = method; +              $scope.url = url; +            }; +          } +        </file> +        <file name="http-hello.html"> +          Hello, $http! +        </file> +        <file name="scenario.js"> +          it('should make an xhr GET request', function() { +            element(':button:contains("Sample GET")').click(); +            element(':button:contains("fetch")').click(); +            expect(binding('status')).toBe('200'); +            expect(binding('data')).toMatch(/Hello, \$http!/); +          }); + +          it('should make a JSONP request to angularjs.org', function() { +            element(':button:contains("Sample JSONP")').click(); +            element(':button:contains("fetch")').click(); +            expect(binding('status')).toBe('200'); +            expect(binding('data')).toMatch(/Super Hero!/); +          }); + +          it('should make JSONP request to invalid URL and invoke the error handler', +              function() { +            element(':button:contains("Invalid JSONP")').click(); +            element(':button:contains("fetch")').click(); +            expect(binding('status')).toBe('0'); +            expect(binding('data')).toBe('Request failed'); +          }); +        </file> +      </example>       */      function $http(config) {        config.method = uppercase(config.method); | 
