Permalink
Browse files

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
  • Loading branch information...
caitp committed Dec 15, 2014
1 parent 630b80f commit 35498d7045ba9138016464a344e2c145ce5264c1
Showing with 416 additions and 90 deletions.
  1. +68 −0 docs/content/error/$compile/noctrl.ngdoc
  2. +3 −0 src/.jshintrc
  3. +159 −87 src/ng/compile.js
  4. +12 −3 src/ng/controller.js
  5. +174 −0 test/ng/compileSpec.js
@@ -0,0 +1,68 @@
@ngdoc error
@name $compile:noctrl
@fullName Controller is required.
@description
When using the `bindToController` feature of AngularJS, a directive is required
to have a Controller, in addition to a controller identifier.
For example, the following directives are valid:
```js
// OKAY, because controller is a string with a label component.

This comment has been minimized.

Show comment
Hide comment
@gkalpak

gkalpak Jan 30, 2015

Member

label -> identifier :)

@gkalpak

gkalpak Jan 30, 2015

Member

label -> identifier :)

directive("okay", function() {
return {
bindToController: true,
controller: "myCtrl as $ctrl"
scope: {
text: "@text"
}
};
});
// OKAY, because the directive uses the controllerAs property to override
// the controller identifier.
directive("okay2", function() {
return {
bindToController: true,
controllerAs: "$ctrl",
controller: function() {
},
scope: {
text: "@text"
}
};
});
```
While the following are invalid:
```js
// BAD, because the controller property is a string with no identifier.
directive("bad", function() {
return {
bindToController: true,
controller: "unlabeledCtrl",
scope: {
text: "@text"
}
};
});
// BAD because the controller is not a string (therefore has no identifier),
// and there is no controllerAs property.
directive("bad2", function() {
return {
bindToController: true,
controller: function noControllerAs() {
},
scope: {
text: "@text"
}
};
});
```
View
@@ -152,6 +152,9 @@
"urlResolve": false,
"urlIsSameOrigin": false,
/* ng/controller.js */
"identifierForController": false,
/* ng/compile.js */
"directiveNormalize": false,
Oops, something went wrong.

0 comments on commit 35498d7

Please sign in to comment.