Skip to content

Commit

Permalink
feat($compile): allow using bindToController as object, support both …
Browse files Browse the repository at this point in the history
…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 angular#10420
  • Loading branch information
caitp committed Dec 15, 2014
1 parent 0524e92 commit 9a97d4b
Show file tree
Hide file tree
Showing 5 changed files with 421 additions and 90 deletions.
68 changes: 68 additions & 0 deletions docs/content/error/$compile/noctrl.ngdoc
Original file line number Diff line number Diff line change
@@ -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.
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"
}
};
});
```
3 changes: 3 additions & 0 deletions src/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@
"urlResolve": false,
"urlIsSameOrigin": false,

/* ng/controller.js */
"identifierForController": false,

/* ng/compile.js */
"directiveNormalize": false,

Expand Down
Loading

0 comments on commit 9a97d4b

Please sign in to comment.