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

Error Descriptions #3459

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/content/error/compile/iscp.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@
@name $compile:iscp
@fullName Invalid Isolate Scope
@description
When {@link guide/directive#directivedefinitionobject declaring isolate scope} the scope definition object must
be in specific format which starts with mode character (`@&=`) with an optional local name.

<pre>
myModule.directive('directiveName', function factory() {
return {
...
scope: {
'attrName': '@', // OK
'attrName2': '=localName', // OK
'attrName3': 'name', // ERROR: missing mode @&=
'attrName4': ' = name', // ERROR: extra spaces
'attrName5': 'name=', // ERROR: must be prefixed with @&=
}
...
}
});
</pre>
9 changes: 9 additions & 0 deletions docs/content/error/compile/multidir.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@
@name $compile:multidir
@fullName Multiple Directive Resource Contention
@description
When multiple directives are triggered on a single DOM element, they may request incompatible/unsupported configuration
which results in this error. The solution is to remove one of the directives which is causing the colsion.

Examples are:

* Multiple `isolated scopes` per element.
* Same `controller name` published more then one directive.
* Multiple directives declared with `transclusion`.
* Multiple directives attempting to defined a `template` or `templateURL`.
4 changes: 0 additions & 4 deletions docs/content/error/compile/noass.ngdoc

This file was deleted.

10 changes: 10 additions & 0 deletions docs/content/error/compile/nodomevents.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
@name $compile:nodomevents
@fullName Interpolated Event Attributes
@description

In this example the `onclick` binding will be ignored. There is no practical value in binding the user input to the
`onclick` event and could result in script injection if the user would enter `javascript:alert('PWND')` into the input
field.
<pre>
<input ng-mode="username">
<div onclick="{{username}}">click me</div>
</pre>

For this reasons we prevent `{{}}` bindings on `formaction` and all attributes which start with `on`.
30 changes: 30 additions & 0 deletions docs/content/error/compile/notassign.ngdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@ngdoc error
@name $compile:notassign
@fullName Non-Assignable Expression
@description

When {@link guide/directive#directivedefinitionobject declaring isolate scope} using the `=` mode the expression
must be assignable.

<pre>
myModule.directive('myDirective', function factory() {
return {
...
scope: {
'bind': '@localValue'
}
...
}
});
</pre>

Example which does not cause error:
<pre>
<my-directive bind="some.property">
</pre>

Examples which will cause errors when the `myDirective` attempts to change the value of `localValue`.
<pre>
<my-directive bind="1+2"> ERROR: this statement makes no sense: 1+2=localValue
<my-directive bind="myFn()"> ERROR: this statement makes no sense: myFn()=localValue
</pre>
10 changes: 10 additions & 0 deletions docs/content/error/compile/selmulti.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
@name $compile:selmulti
@fullName Binding to Multiple Attribute
@description

Binding to `multiple` on select is not allowed since switching between multiple and single mode changes the `ng-model`
object type from instance to array of instances which breaks the model semantics. Use
{@link api/ng.directive:ngSwitch ng-switch} directive to work around this issue and allow different `ng-model`
definitions for single and multiple mode.

<pre>
<select ng-model="" multiple="{{mode}}" ng-options="..."></select>
</pre>

25 changes: 25 additions & 0 deletions docs/content/error/compile/tplrt.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,28 @@
@name $compile:tplrt
@fullName Invalid Template Root
@description
When a directive is declared with template and replace mode on, it must have exactly one root element. Otherwise the
replacement would cause the containing element to grow in number of children which would then break directive
offsets.

<pre>
myModule.directive('myDirective', function factory() {
return {
...
replace: true,
templateUrl: 'someUrl'
...
}
});
</pre>

This template is OK as it has one root element `<div>`.
<pre>
<div><b>Hello</b> World!</div>
</pre>

This template will cause an error since it has multiple roots. (The `<b>` element and the `#text` nodes are the two
top level nodes.
<pre>
<b>Hello</b> World!
</pre>
4 changes: 2 additions & 2 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ function $CompileProvider($provide) {
parentSet = parentGet.assign || function() {
// reset the change, or we will throw this exception on every $digest
lastValue = scope[scopeName] = parentGet(parentScope);
throw $compileMinErr('noass', "Expression '{0}' used with directive '{1}' is non-assignable!",
throw $compileMinErr('notassign', "Expression '{0}' used with directive '{1}' is non-assignable!",
attrs[attrName], newIsolateScopeDirective.name);
};
lastValue = scope[scopeName] = parentGet(parentScope);
Expand Down Expand Up @@ -1229,7 +1229,7 @@ function $CompileProvider($provide) {


if (name === "multiple" && nodeName_(node) === "SELECT") {
throw $compileMinErr("selmulti", "Binding to the multiple attribute is not supported. Element: {0}",
throw $compileMinErr("selmulti", "Binding to the 'multiple' attribute is not supported. Element: {0}",
startingTag(node));
}

Expand Down
2 changes: 1 addition & 1 deletion test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,7 @@ describe('$compile', function() {

componentScope.ref = 'ignore me';
expect($rootScope.$apply).
toThrow("[$compile:noass] Expression ''hello ' + name' used with directive 'myComponent' is non-assignable!");
toThrow("[$compile:notassign] Expression ''hello ' + name' used with directive 'myComponent' is non-assignable!");
expect(componentScope.ref).toBe('hello world');
// reset since the exception was rethrown which prevented phase clearing
$rootScope.$$phase = null;
Expand Down
2 changes: 1 addition & 1 deletion test/ng/directive/booleanAttrsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('boolean attr directives', function() {

expect(function() {
$compile('<select multiple="{{isMultiple}}"></select>')
}).toThrow('[$compile:selmulti] Binding to the multiple attribute is not supported. ' +
}).toThrow('[$compile:selmulti] Binding to the \'multiple\' attribute is not supported. ' +
'Element: <select multiple="{{isMultiple}}">');

}));
Expand Down