This repository was 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.4k
feat($compile): allow using bindToController as object, support both new/isolate scopes #10467
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ee11ced
feat($compile): allow using bindToController as object, support both …
caitp 4916d27
fix($compile): respect return value from controller constructor
caitp 4ed70af
docs($compile): create new error for "missing controller identifier"
caitp fcaca73
docs($compile,$route): reword "controller alias" to clarify
caitp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,12 @@ | ||
@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. A controller may be specified by adding a "controller" | ||
property to the directive definition object. Its value should be either a | ||
string, or an invokable object (a function, or an array whose last element is a | ||
function). | ||
|
||
For more information, see the {@link guide/directive directives guide}. |
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,71 @@ | ||
@ngdoc error | ||
@name $compile:noident | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
@fullName Controller identifier is required. | ||
@description | ||
|
||
When using the `bindToController` feature of AngularJS, a directive is required | ||
to have a Controller identifier, which is initialized in scope with the value of | ||
the controller instance. This can be supplied using the "controllerAs" property | ||
of the directive object, or alternatively by adding " as IDENTIFIER" to the controller | ||
name. | ||
|
||
For example, the following directives are valid: | ||
|
||
```js | ||
// OKAY, because controller is a string with an identifier 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // the controller alias |
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // BAD, because the controller property is a string with no alias. |
||
directive("bad", function() { | ||
return { | ||
bindToController: true, | ||
controller: "noIdentCtrl", | ||
scope: { | ||
text: "@text" | ||
} | ||
}; | ||
}); | ||
|
||
|
||
// BAD because the controller is not a string (therefore has no identifier), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // BAD because the controller is not a string (therefore has no alias), |
||
// 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,9 @@ | |
"urlResolve": false, | ||
"urlIsSameOrigin": false, | ||
|
||
/* ng/controller.js */ | ||
"identifierForController": false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "aliasForController": false, |
||
|
||
/* ng/compile.js */ | ||
"directiveNormalize": false, | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this full name be more like:
"controller as" identifier required to bind to controller
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am not mitaken, this error will also be thrown if there is
bindToController: true
but nocontroler:...
. So the literals have to account for all cases (i.e.bindToController: true
but nocontroller
or no controller identifier).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I see that now. I was thrown by the main body of the error document, which doesn't really mention that aspect of the error at all.
I wonder if we ought to have two separate errors?