Skip to content

Commit bee75c2

Browse files
Merge pull request #158 from angular/master
Update upstream
2 parents 07d2e18 + 74726b4 commit bee75c2

File tree

4 files changed

+94
-120
lines changed

4 files changed

+94
-120
lines changed

CHANGELOG.md

+31-2
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ This in turn affects how dirty checking treats objects that prototypally
448448
inherit from `Array` (e.g. MobX observable arrays). AngularJS will now
449449
be able to handle these objects better when copying or watching.
450450

451-
### **$sce** due to:
452-
- **[1e9ead](https://github.com/angular/angular.js/commit/1e9eadcd72dbbd5c67dae8328a63e535cfa91ff9)**: handle URL sanitization through the `$sce` service
451+
### **$sce** :
452+
- due to **[1e9ead](https://github.com/angular/angular.js/commit/1e9eadcd72dbbd5c67dae8328a63e535cfa91ff9)**: handle URL sanitization through the `$sce` service
453453

454454
If you use `attrs.$set` for URL attributes (a[href] and img[src]) there will no
455455
longer be any automated sanitization of the value. This is in line with other
@@ -463,6 +463,35 @@ Note that values that have been passed through the `$interpolate` service within
463463
`URL` or `MEDIA_URL` will have already been sanitized, so you would not need to sanitize
464464
these values again.
465465

466+
- due to **[1e9ead](https://github.com/angular/angular.js/commit/1e9eadcd72dbbd5c67dae8328a63e535cfa91ff9)**: handle URL sanitization through the `$sce` service
467+
468+
binding `trustAs()` and the short versions (`trustAsResourceUrl()` et al.) to
469+
`ngSrc`, `ngSrcset`, and `ngHref` will now raise an infinite digest error:
470+
471+
```js
472+
$scope.imgThumbFn = function(id) {
473+
return $sce.trustAsResourceUrl(someService.someUrl(id));
474+
};
475+
```
476+
477+
```html
478+
<img ng-src="{{imgThumbFn(imgId)}}">
479+
```
480+
This is because the `$interpolate` service is now responsible for sanitizing
481+
the attribute value, and its watcher receives a new object from `trustAs()`
482+
on every digest.
483+
To migrate, compute the trusted value only when the input value changes:
484+
485+
```js
486+
$scope.$watch('imgId', function(id) {
487+
$scope.imgThumb = $sce.trustAsResourceUrl(someService.someUrl(id));
488+
});
489+
```
490+
491+
```html
492+
<img ng-src="{{imgThumb}}">
493+
```
494+
466495
### **orderBy** due to:
467496
- **[1d8046](https://github.com/angular/angular.js/commit/1d804645f7656d592c90216a0355b4948807f6b8)**: consider `null` and `undefined` greater than other values
468497

docs/content/guide/$location.ngdoc

+32-116
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@sortOrder 500
44
@description
55

6-
# What does it do?
6+
# Using the `$location` service
77

88
The `$location` service parses the URL in the browser address bar (based on [`window.location`](https://developer.mozilla.org/en/window.location)) and makes the URL available to
99
your application. Changes to the URL in the address bar are reflected into the `$location` service and
@@ -76,7 +76,7 @@ the current URL in the browser.
7676
It does not cause a full page reload when the browser URL is changed. To reload the page after
7777
changing the URL, use the lower-level API, `$window.location.href`.
7878

79-
# General overview of the API
79+
## General overview of the API
8080

8181
The `$location` service can behave differently, depending on the configuration that was provided to
8282
it when it was instantiated. The default configuration is suitable for many applications, for
@@ -85,7 +85,7 @@ others customizing the configuration can enable new features.
8585
Once the `$location` service is instantiated, you can interact with it via jQuery-style getter and
8686
setter methods that allow you to get or change the current URL in the browser.
8787

88-
## `$location` service configuration
88+
### `$location` service configuration
8989

9090
To configure the `$location` service, retrieve the
9191
{@link ng.$locationProvider $locationProvider} and set the parameters as follows:
@@ -113,12 +113,12 @@ To configure the `$location` service, retrieve the
113113
Prefix used for Hashbang URLs (used in Hashbang mode or in legacy browsers in HTML5 mode).<br />
114114
Default: `'!'`
115115

116-
### Example configuration
116+
#### Example configuration
117117
```js
118118
$locationProvider.html5Mode(true).hashPrefix('*');
119119
```
120120

121-
## Getter and setter methods
121+
### Getter and setter methods
122122

123123
`$location` service provides getter methods for read-only parts of the URL (absUrl, protocol, host,
124124
port) and getter / setter methods for url, path, search, hash:
@@ -137,7 +137,7 @@ change multiple segments in one go, chain setters like this:
137137
$location.path('/newValue').search({key: value});
138138
```
139139

140-
## Replace method
140+
### Replace method
141141

142142
There is a special `replace` method which can be used to tell the $location service that the next
143143
time the $location service is synced with the browser, the last history record should be replaced
@@ -173,7 +173,7 @@ encoded.
173173
`/path?search=a&b=c#hash`. The segments are encoded as well.
174174

175175

176-
# Hashbang and HTML5 Modes
176+
## Hashbang and HTML5 Modes
177177

178178
`$location` service has two configuration modes which control the format of the URL in the browser
179179
address bar: **Hashbang mode** (the default) and the **HTML5 mode** which is based on using the
@@ -221,15 +221,15 @@ facilitate the browser URL change and history management.
221221
</tbody>
222222
</table>
223223

224-
## Hashbang mode (default mode)
224+
### Hashbang mode (default mode)
225225

226226
In this mode, `$location` uses Hashbang URLs in all browsers.
227227
AngularJS also does not intercept and rewrite links in this mode. I.e. links work
228228
as expected and also perform full page reloads when other parts of the url
229229
than the hash fragment was changed.
230230

231231

232-
### Example
232+
#### Example
233233

234234
```js
235235
it('should show example', function() {
@@ -255,7 +255,7 @@ it('should show example', function() {
255255
});
256256
```
257257

258-
## HTML5 mode
258+
### HTML5 mode
259259

260260
In HTML5 mode, the `$location` service getters and setters interact with the browser URL address
261261
through the HTML5 history API. This allows for use of regular URL path and search segments,
@@ -271,7 +271,7 @@ Note that in this mode, AngularJS intercepts all links (subject to the "Html lin
271271
and updates the url in a way that never performs a full page reload.
272272

273273

274-
### Example
274+
#### Example
275275

276276
```js
277277
it('should show example', function() {
@@ -320,14 +320,14 @@ it('should show example (when browser doesn\'t support HTML5 mode', function() {
320320
});
321321
```
322322

323-
### Fallback for legacy browsers
323+
#### Fallback for legacy browsers
324324

325325
For browsers that support the HTML5 history API, `$location` uses the HTML5 history API to write
326326
path and search. If the history API is not supported by a browser, `$location` supplies a Hashbang
327327
URL. This frees you from having to worry about whether the browser viewing your app supports the
328328
history API or not; the `$location` service makes this transparent to you.
329329

330-
### HTML link rewriting
330+
#### HTML link rewriting
331331

332332
When you use HTML5 history API mode, you will not need special hashbang links. All you have to do
333333
is specify regular URL links, such as: `<a href="/some?foo=bar">link</a>`
@@ -361,7 +361,7 @@ Note that [attribute name normalization](guide/directive#normalization) does not
361361
`'internalLink'` will **not** match `'internal-link'`.
362362

363363

364-
### Relative links
364+
#### Relative links
365365

366366
Be sure to check all relative links, images, scripts etc. AngularJS requires you to specify the url
367367
base in the head of your main html file (`<base href="/my-base/index.html">`) unless `html5Mode.requireBase`
@@ -374,14 +374,14 @@ will only change `$location.hash()` and not modify the url otherwise. This is us
374374
to anchors on the same page without needing to know on which page the user currently is.
375375

376376

377-
### Server side
377+
#### Server side
378378

379379
Using this mode requires URL rewriting on server side, basically you have to rewrite all your links
380380
to entry point of your application (e.g. index.html). Requiring a `<base>` tag is also important for
381381
this case, as it allows AngularJS to differentiate between the part of the url that is the application
382382
base and the path that should be handled by the application.
383383

384-
### Base href constraints
384+
#### Base href constraints
385385

386386
The `$location` service is not able to function properly if the current URL is outside the URL given
387387
as the base href. This can have subtle confusing consequences...
@@ -403,7 +403,7 @@ legacy browsers and hashbang links in modern browser:
403403
- Modern browser will rewrite hashbang URLs to regular URLs.
404404
- Older browsers will redirect regular URLs to hashbang URLs.
405405

406-
### Example
406+
#### Example
407407

408408
Here you can see two `$location` instances that show the difference between **Html5 mode** and **Html5 Fallback mode**.
409409
Note that to simulate different levels of browser support, the `$location` instances are connected to
@@ -415,7 +415,7 @@ redirect to regular / hashbang url, as this conversion happens only during parsi
415415

416416
In these examples we use `<base href="/base/index.html" />`. The inputs represent the address bar of the browser.
417417

418-
#### Browser in HTML5 mode
418+
##### Browser in HTML5 mode
419419
<example module="html5-mode" name="location-html5-mode">
420420
<file name="index.html">
421421
<div ng-controller="LocationController">
@@ -565,7 +565,7 @@ In these examples we use `<base href="/base/index.html" />`. The inputs represen
565565

566566
</example>
567567

568-
#### Browser in HTML5 Fallback mode (Hashbang mode)
568+
##### Browser in HTML5 Fallback mode (Hashbang mode)
569569
<example module="hashbang-mode" name="location-hashbang-mode">
570570
<file name="index.html">
571571
<div ng-controller="LocationController">
@@ -718,15 +718,15 @@ In these examples we use `<base href="/base/index.html" />`. The inputs represen
718718

719719
</example>
720720

721-
# Caveats
721+
## Caveats
722722

723-
## Page reload navigation
723+
### Page reload navigation
724724

725725
The `$location` service allows you to change only the URL; it does not allow you to reload the
726726
page. When you need to change the URL and reload the page or navigate to a different page, please
727727
use a lower level API, {@link ng.$window $window.location.href}.
728728

729-
## Using $location outside of the scope life-cycle
729+
### Using $location outside of the scope life-cycle
730730

731731
`$location` knows about AngularJS's {@link ng.$rootScope.Scope scope} life-cycle. When a URL changes in
732732
the browser it updates the `$location` and calls `$apply` so that all
@@ -738,30 +738,25 @@ propagate this change into browser and will notify all the {@link ng.$rootScope.
738738
When you want to change the `$location` from outside AngularJS (for example, through a DOM Event or
739739
during testing) - you must call `$apply` to propagate the changes.
740740

741-
## $location.path() and ! or / prefixes
741+
### $location.path() and ! or / prefixes
742742

743743
A path should always begin with forward slash (`/`); the `$location.path()` setter will add the
744744
forward slash if it is missing.
745745

746746
Note that the `!` prefix in the hashbang mode is not part of `$location.path()`; it is actually
747747
`hashPrefix`.
748748

749-
## Crawling your app
749+
### Crawling your app
750750

751-
To allow indexing of your AJAX application, you have to add special meta tag in the head section of
752-
your document:
753-
754-
```html
755-
<meta name="fragment" content="!" />
756-
```
757-
758-
This will cause crawler bot to request links with `_escaped_fragment_` param so that your server
759-
can recognize the crawler and serve a HTML snapshots. For more information about this technique,
760-
see [Making AJAX Applications
761-
Crawlable](http://code.google.com/web/ajaxcrawling/docs/specification.html).
751+
Most modern search engines are able to crawl AJAX applications with dynamic content, provided all
752+
included resources are available to the crawler bots.
762753

754+
There also exists a special
755+
[AJAX crawling scheme](http://code.google.com/web/ajaxcrawling/docs/specification.html) developed by
756+
Google that allows bots to crawl the static equivalent of a dynamically generated page,
757+
but this schema has been deprecated, and support for it may vary by search engine.
763758

764-
# Testing with the $location service
759+
## Testing with the $location service
765760

766761
When using `$location` service during testing, you are outside of the angular's {@link
767762
ng.$rootScope.Scope scope} life-cycle. This means it's your responsibility to call `scope.$apply()`.
@@ -784,85 +779,6 @@ describe('serviceUnderTest', function() {
784779
});
785780
```
786781

787-
788-
# Migrating from earlier AngularJS releases
789-
790-
In earlier releases of AngularJS, `$location` used `hashPath` or `hashSearch` to process path and
791-
search methods. With this release, the `$location` service processes path and search methods and
792-
then uses the information it obtains to compose hashbang URLs (such as
793-
`http://server.com/#!/path?search=a`), when necessary.
794-
795-
## Changes to your code
796-
797-
<table class="table">
798-
<thead>
799-
<tr class="head">
800-
<th>Navigation inside the app</th>
801-
<th>Change to</th>
802-
</tr>
803-
</thead>
804-
805-
<tbody>
806-
<tr>
807-
<td>$location.href = value<br />$location.hash = value<br />$location.update(value)<br
808-
/>$location.updateHash(value)</td>
809-
<td>$location.path(path).search(search)</td>
810-
</tr>
811-
812-
<tr>
813-
<td>$location.hashPath = path</td>
814-
<td>$location.path(path)</td>
815-
</tr>
816-
817-
<tr>
818-
<td>$location.hashSearch = search</td>
819-
<td>$location.search(search)</td>
820-
</tr>
821-
822-
<tr class="head">
823-
<th>Navigation outside the app</td>
824-
<th>Use lower level API</td>
825-
</tr>
826-
827-
<tr>
828-
<td>$location.href = value<br />$location.update(value)</td>
829-
<td>$window.location.href = value</td>
830-
</tr>
831-
832-
<tr>
833-
<td>$location[protocol | host | port | path | search]</td>
834-
<td>$window.location[protocol | host | port | path | search]</td>
835-
</tr>
836-
837-
<tr class="head">
838-
<th>Read access</td>
839-
<th>Change to</td>
840-
</tr>
841-
842-
<tr>
843-
<td>$location.hashPath</td>
844-
<td>$location.path()</td>
845-
</tr>
846-
847-
<tr>
848-
<td>$location.hashSearch</td>
849-
<td>$location.search()</td>
850-
</tr>
851-
852-
<tr>
853-
<td>$location.href<br />$location.protocol<br />$location.host<br />$location.port<br
854-
/>$location.hash</td>
855-
<td>$location.absUrl()<br />$location.protocol()<br />$location.host()<br />$location.port()<br
856-
/>$location.path() + $location.search()</td>
857-
</tr>
858-
859-
<tr>
860-
<td>$location.path<br />$location.search</td>
861-
<td>$window.location.path<br />$window.location.search</td>
862-
</tr>
863-
</tbody>
864-
</table>
865-
866782
## Two-way binding to $location
867783

868784
Because `$location` uses getters/setters, you can use `ng-model-options="{ getterSetter: true }"`
@@ -884,6 +800,6 @@ angular.module('locationExample', [])
884800
</file>
885801
</example>
886802

887-
# Related API
803+
## Related API
888804

889805
* {@link ng.$location `$location` API}

0 commit comments

Comments
 (0)