Skip to content

Commit ced4b6f

Browse files
Merge pull request #48 from angular/master
Update upstream
2 parents 5830c82 + b86876c commit ced4b6f

File tree

9 files changed

+47
-41
lines changed

9 files changed

+47
-41
lines changed

docs/content/guide/controller.ngdoc

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88
In AngularJS, a Controller is defined by a JavaScript **constructor function** that is used to augment the
99
{@link scope AngularJS Scope}.
1010

11-
When a Controller is attached to the DOM via the {@link ng.directive:ngController ng-controller}
12-
directive, AngularJS will instantiate a new Controller object, using the specified Controller's
13-
**constructor function**. A new **child scope** will be created and made available as an injectable
14-
parameter to the Controller's constructor function as `$scope`.
11+
Controllers can be attached to the DOM in different ways. For each of them, AngularJS will
12+
instantiate a new Controller object, using the specified Controller's **constructor function**:
13+
14+
- the {@link ng.directive:ngController ngController} directive. A new **child scope** will be
15+
created and made available as an injectable parameter to the Controller's constructor function
16+
as `$scope`.
17+
- a route controller in a {@link ngRoute.$routeProvider $route definition}.
18+
- the controller of a {@link guide/directive regular directive}, or a
19+
{@link guide/component component directive}.
1520

1621
If the controller has been attached using the `controller as` syntax then the controller instance will
17-
be assigned to a property on the new scope.
22+
be assigned to a property on the scope.
1823

1924
Use controllers to:
2025

@@ -33,6 +38,15 @@ Do not use controllers to:
3338
services} instead.
3439
- Manage the life-cycle of other components (for example, to create service instances).
3540

41+
In general, a Controller shouldn't try to do too much. It should contain only the business logic
42+
needed for a single view.
43+
44+
The most common way to keep Controllers slim is by encapsulating work that doesn't belong to
45+
controllers into services and then using these services in Controllers via dependency injection.
46+
This is discussed in the {@link di Dependency Injection} and {@link services
47+
Services} sections of this guide.
48+
49+
3650
## Setting up the initial state of a `$scope` object
3751

3852
Typically, when you create an application you need to set up the initial state for the AngularJS
@@ -102,23 +116,6 @@ objects (or primitives) assigned to the scope become model properties. Any metho
102116
the scope are available in the template/view, and can be invoked via AngularJS expressions
103117
and `ng` event handler directives (e.g. {@link ng.directive:ngClick ngClick}).
104118

105-
## Using Controllers Correctly
106-
107-
In general, a Controller shouldn't try to do too much. It should contain only the business logic
108-
needed for a single view.
109-
110-
The most common way to keep Controllers slim is by encapsulating work that doesn't belong to
111-
controllers into services and then using these services in Controllers via dependency injection.
112-
This is discussed in the {@link di Dependency Injection} and {@link services
113-
Services} sections of this guide.
114-
115-
116-
# Associating Controllers with AngularJS Scope Objects
117-
118-
You can associate Controllers with scope objects implicitly via the {@link ng.directive:ngController ngController
119-
directive} or {@link ngRoute.$route $route service}.
120-
121-
122119
## Simple Spicy Controller Example
123120

124121
To illustrate further how Controller components work in AngularJS, let's create a little app with the
@@ -262,7 +259,7 @@ Inheritance works with methods in the same way as it does with properties. So in
262259
examples, all of the properties could be replaced with methods that return string values.
263260

264261

265-
# Testing Controllers
262+
## Testing Controllers
266263

267264
Although there are many ways to test a Controller, one of the best conventions, shown below,
268265
involves injecting the {@link ng.$rootScope $rootScope} and {@link ng.$controller $controller}:

karma-shared.conf.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ module.exports = function(config, specificOptions) {
6262
browserName: 'firefox',
6363
version: 'latest-1'
6464
},
65-
'SL_Safari_8': {
65+
'SL_Safari-1': {
6666
base: 'SauceLabs',
6767
browserName: 'safari',
68-
platform: 'OS X 10.10',
69-
version: '8'
68+
platform: 'OS X 10.12',
69+
version: 'latest-1'
7070
},
71-
'SL_Safari_9': {
71+
'SL_Safari': {
7272
base: 'SauceLabs',
7373
browserName: 'safari',
74-
platform: 'OS X 10.11',
75-
version: '9'
74+
platform: 'OS X 10.12',
75+
version: 'latest'
7676
},
7777
'SL_IE_9': {
7878
base: 'SauceLabs',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"rewire": "~2.1.0",
8888
"sax": "^1.1.1",
8989
"selenium-webdriver": "^2.53.1",
90-
"semver": "~4.0.3",
90+
"semver": "^5.4.1",
9191
"serve-favicon": "^2.3.0",
9292
"serve-index": "^1.8.0",
9393
"serve-static": "^1.11.1",

scripts/travis/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SAUCE_ACCESS_KEY=$(echo "$SAUCE_ACCESS_KEY" | rev)
1010

1111
BROWSERS="SL_Chrome,SL_Chrome-1,\
1212
SL_Firefox,SL_Firefox-1,\
13-
SL_Safari_8,SL_Safari_9,\
13+
SL_Safari,SL_Safari-1,\
1414
SL_iOS,\
1515
SL_IE_9,SL_IE_10,SL_IE_11,\
1616
SL_EDGE,SL_EDGE-1"

src/ngSanitize/sanitize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ function $SanitizeProvider() {
269269
optionalEndTagElements);
270270

271271
//Attributes that have href and hence need to be sanitized
272-
var uriAttrs = toMap('background,cite,href,longdesc,src,xlink:href');
272+
var uriAttrs = toMap('background,cite,href,longdesc,src,xlink:href,xml:base');
273273

274274
var htmlAttrs = toMap('abbr,align,alt,axis,bgcolor,border,cellpadding,cellspacing,class,clear,' +
275275
'color,cols,colspan,compact,coords,dir,face,headers,height,hreflang,hspace,' +

test/ng/directive/ngOptionsSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,13 +2922,13 @@ describe('ngOptions', function() {
29222922
});
29232923

29242924

2925-
// Support: Safari 9
2925+
// Support: Safari 9+
29262926
// This test relies defining a getter/setter `selected` property on either `<option>` elements
29272927
// or their prototype. Some browsers (including Safari 9) are very flakey when the
29282928
// getter/setter is not defined on the prototype (probably due to some bug). On Safari 9, the
29292929
// getter/setter that is already defined on the `<option>` element's prototype is not
29302930
// configurable, so we can't overwrite it with our spy.
2931-
if (!/\b9(?:\.\d+)+ safari/i.test(window.navigator.userAgent)) {
2931+
if (!/\b(9|\d{2})(?:\.\d+)+ safari/i.test(window.navigator.userAgent)) {
29322932
it('should not re-set the `selected` property if it already has the correct value', function() {
29332933
scope.values = [{name: 'A'}, {name: 'B'}];
29342934
createMultiSelect();

test/ngMock/angular-mocksSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ describe('ngMock', function() {
10071007
})();
10081008

10091009
function testCaller() {
1010-
return inject(function() {
1010+
return inject(function injectableError() {
10111011
throw new Error();
10121012
});
10131013
}
@@ -1019,7 +1019,7 @@ describe('ngMock', function() {
10191019
try {
10201020
throwErrorFromInjectCallback();
10211021
} catch (e) {
1022-
expect(e.stack).toMatch('testCaller');
1022+
expect(e.stack).toMatch('injectableError');
10231023
}
10241024
});
10251025
});

test/ngSanitize/sanitizeSpec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,15 @@ describe('HTML', function() {
327327
'<svg xmlns="http://www.w3.org/2000/svg"><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://example.com"></a></svg>');
328328
});
329329

330+
it('should sanitize SVG xml:base attribute values', function() {
331+
expectHTML('<svg xmlns="http://www.w3.org/2000/svg"><a xml:base="javascript:alert(1)//" href="#"></a></svg>')
332+
.toEqual('<svg xmlns="http://www.w3.org/2000/svg"><a href="#"></a></svg>');
333+
334+
expectHTML('<svg xmlns="http://www.w3.org/2000/svg"><a xml:base="https://example.com" href="#"></a></svg>')
335+
.toEqual('<svg xmlns="http://www.w3.org/2000/svg"><a xml:base="https://example.com" href="#"></a></svg>');
336+
337+
});
338+
330339
it('should sanitize unknown namespaced SVG attributes', function() {
331340
expectHTML('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:foo="javascript:alert()"></a></svg>')
332341
.toBeOneOf('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>',

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ backo2@1.0.2:
411411
version "1.0.2"
412412
resolved "https://registry.yarnpkg.com/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947"
413413

414+
balanced-match@^0.4.1:
415+
version "0.4.2"
416+
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838"
417+
414418
balanced-match@^1.0.0:
415419
version "1.0.0"
416420
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
@@ -5904,14 +5908,10 @@ semver@^4.1.0, semver@~4.3.3:
59045908
version "4.3.6"
59055909
resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.6.tgz#300bc6e0e86374f7ba61068b5b1ecd57fc6532da"
59065910

5907-
semver@^5.3.0:
5911+
semver@^5.3.0, semver@^5.4.1:
59085912
version "5.4.1"
59095913
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"
59105914

5911-
semver@~4.0.3:
5912-
version "4.0.3"
5913-
resolved "https://registry.yarnpkg.com/semver/-/semver-4.0.3.tgz#f79c9ba670efccc029d98a5017def64b0ce1644e"
5914-
59155915
semver@~5.0.1:
59165916
version "5.0.3"
59175917
resolved "https://registry.yarnpkg.com/semver/-/semver-5.0.3.tgz#77466de589cd5d3c95f138aa78bc569a3cb5d27a"

0 commit comments

Comments
 (0)