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

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 #10420
Closes #10467
  • Loading branch information
caitp committed Jan 29, 2015
1 parent 630b80f commit 35498d7
Show file tree
Hide file tree
Showing 5 changed files with 416 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.

This comment has been minimized.

Copy link
@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"
}
};
});
```
3 changes: 3 additions & 0 deletions src/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@
"urlResolve": false,
"urlIsSameOrigin": false,

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

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

Expand Down
Loading

0 comments on commit 35498d7

Please sign in to comment.