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

Commit 78a445f

Browse files
mheveryIgorMinar
authored andcommitted
docs(compile/notassign): description for compile/notassign error
Closes #3459
1 parent 4e76d04 commit 78a445f

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

docs/content/error/compile/noass.ngdoc

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@ngdoc error
2+
@name $compile:nonassign
3+
@fullName Non-Assignable Expression
4+
@description
5+
6+
This error occurs when a directive defines an isolate scope property that support two-way data-binding (using the `=` mode in the {@link guide/directive#directivedefinitionobject directive definition}) but the directive is used with an expression that is not-assignable.
7+
8+
In order for the two-way data-binding to work, it must be possible to write new values back into the path defined with the expression.
9+
10+
For example, given a directive:
11+
12+
```
13+
myModule.directive('myDirective', function factory() {
14+
return {
15+
...
16+
scope: {
17+
'bind': '=localValue'
18+
}
19+
...
20+
}
21+
});
22+
```
23+
24+
Following are invalid uses of this directive:
25+
```
26+
<my-directive bind="1+2"> <!-- ERROR because `1+2=localValue` is an invalid statement -->
27+
<my-directive bind="myFn()"> <!-- ERROR because `myFn()=localValue` is an invalid statement -->
28+
```
29+
30+
31+
To resolve this error, always use path expressions with scope properties that are two-way data-bound:
32+
```
33+
<my-directive bind="some.property">
34+
<my-directive bind="some[3]['property']">
35+
```
36+

src/ng/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ function $CompileProvider($provide) {
978978
parentSet = parentGet.assign || function() {
979979
// reset the change, or we will throw this exception on every $digest
980980
lastValue = scope[scopeName] = parentGet(parentScope);
981-
throw $compileMinErr('noass', "Expression '{0}' used with directive '{1}' is non-assignable!",
981+
throw $compileMinErr('nonassign', "Expression '{0}' used with directive '{1}' is non-assignable!",
982982
attrs[attrName], newIsolateScopeDirective.name);
983983
};
984984
lastValue = scope[scopeName] = parentGet(parentScope);

test/ng/compileSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,7 @@ describe('$compile', function() {
21102110

21112111
componentScope.ref = 'ignore me';
21122112
expect($rootScope.$apply).
2113-
toThrow("[$compile:noass] Expression ''hello ' + name' used with directive 'myComponent' is non-assignable!");
2113+
toThrow("[$compile:nonassign] Expression ''hello ' + name' used with directive 'myComponent' is non-assignable!");
21142114
expect(componentScope.ref).toBe('hello world');
21152115
// reset since the exception was rethrown which prevented phase clearing
21162116
$rootScope.$$phase = null;
@@ -3240,7 +3240,7 @@ describe('$compile', function() {
32403240
};
32413241
});
32423242
});
3243-
inject(function($compile, $rootScope) {
3243+
inject(function($compile) {
32443244
expect(function() {
32453245
element = $compile(
32463246
'<div>' +

0 commit comments

Comments
 (0)