Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 35498d7

Browse files
committed
feat($compile): allow using bindToController as object, support both new/isolate scopes
bindToController is now able to be specified as a convenient object notation: ``` bindToController: { text: '@text', obj: '=obj', expr: '&expr' }, scope: {} ``` It can also be used in conjunction with new scopes, rather than exclusively isolate scopes: ``` bindToController: { text: '@text', obj: '=obj', expr: '&expr' }, scope: true ``` Closes #10420 Closes #10467
1 parent 630b80f commit 35498d7

File tree

5 files changed

+416
-90
lines changed

5 files changed

+416
-90
lines changed
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
@ngdoc error
2+
@name $compile:noctrl
3+
@fullName Controller is required.
4+
@description
5+
6+
When using the `bindToController` feature of AngularJS, a directive is required
7+
to have a Controller, in addition to a controller identifier.
8+
9+
For example, the following directives are valid:
10+
11+
```js
12+
// OKAY, because controller is a string with a label component.
13+
directive("okay", function() {
14+
return {
15+
bindToController: true,
16+
controller: "myCtrl as $ctrl"
17+
scope: {
18+
text: "@text"
19+
}
20+
};
21+
});
22+
23+
24+
// OKAY, because the directive uses the controllerAs property to override
25+
// the controller identifier.
26+
directive("okay2", function() {
27+
return {
28+
bindToController: true,
29+
controllerAs: "$ctrl",
30+
controller: function() {
31+
32+
},
33+
scope: {
34+
text: "@text"
35+
}
36+
};
37+
});
38+
```
39+
40+
While the following are invalid:
41+
42+
```js
43+
// BAD, because the controller property is a string with no identifier.
44+
directive("bad", function() {
45+
return {
46+
bindToController: true,
47+
controller: "unlabeledCtrl",
48+
scope: {
49+
text: "@text"
50+
}
51+
};
52+
});
53+
54+
55+
// BAD because the controller is not a string (therefore has no identifier),
56+
// and there is no controllerAs property.
57+
directive("bad2", function() {
58+
return {
59+
bindToController: true,
60+
controller: function noControllerAs() {
61+
62+
},
63+
scope: {
64+
text: "@text"
65+
}
66+
};
67+
});
68+
```

src/.jshintrc

+3
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@
152152
"urlResolve": false,
153153
"urlIsSameOrigin": false,
154154

155+
/* ng/controller.js */
156+
"identifierForController": false,
157+
155158
/* ng/compile.js */
156159
"directiveNormalize": false,
157160

0 commit comments

Comments
 (0)