This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
5 changed files
with
416 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong. |
||
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" | ||
} | ||
}; | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
label -> identifier :)