diff --git a/docs/content/error/compile/iscp.ngdoc b/docs/content/error/compile/iscp.ngdoc index afdbd4c4e8d..3c5c3208a6a 100644 --- a/docs/content/error/compile/iscp.ngdoc +++ b/docs/content/error/compile/iscp.ngdoc @@ -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. + +
+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 @&=
+    }
+    ...
+  }
+});
+
diff --git a/docs/content/error/compile/multidir.ngdoc b/docs/content/error/compile/multidir.ngdoc index 4e893c3e555..f9583e0162a 100644 --- a/docs/content/error/compile/multidir.ngdoc +++ b/docs/content/error/compile/multidir.ngdoc @@ -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`. diff --git a/docs/content/error/compile/noass.ngdoc b/docs/content/error/compile/noass.ngdoc deleted file mode 100644 index bb247499ec5..00000000000 --- a/docs/content/error/compile/noass.ngdoc +++ /dev/null @@ -1,4 +0,0 @@ -@ngdoc error -@name $compile:noass -@fullName Non-Assignable Expression -@description diff --git a/docs/content/error/compile/nodomevents.ngdoc b/docs/content/error/compile/nodomevents.ngdoc index 421e896f249..3a3bad70918 100644 --- a/docs/content/error/compile/nodomevents.ngdoc +++ b/docs/content/error/compile/nodomevents.ngdoc @@ -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. +
+
+
click me
+
+ +For this reasons we prevent `{{}}` bindings on `formaction` and all attributes which start with `on`. diff --git a/docs/content/error/compile/notassign.ngdoc b/docs/content/error/compile/notassign.ngdoc new file mode 100644 index 00000000000..429125ec57f --- /dev/null +++ b/docs/content/error/compile/notassign.ngdoc @@ -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. + +
+myModule.directive('myDirective', function factory() {
+  return {
+    ...
+    scope: {
+      'bind': '@localValue'
+    }
+    ...
+  }
+});
+
+ +Example which does not cause error: +
+  
+
+ +Examples which will cause errors when the `myDirective` attempts to change the value of `localValue`. +
+   ERROR: this statement makes no sense: 1+2=localValue
+   ERROR: this statement makes no sense: myFn()=localValue
+
diff --git a/docs/content/error/compile/selmulti.ngdoc b/docs/content/error/compile/selmulti.ngdoc index d737ca35511..f3744af429c 100644 --- a/docs/content/error/compile/selmulti.ngdoc +++ b/docs/content/error/compile/selmulti.ngdoc @@ -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. + +
+
+
+ diff --git a/docs/content/error/compile/tplrt.ngdoc b/docs/content/error/compile/tplrt.ngdoc index 4afd88cd20f..e5cfa3e658d 100644 --- a/docs/content/error/compile/tplrt.ngdoc +++ b/docs/content/error/compile/tplrt.ngdoc @@ -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. + +
+myModule.directive('myDirective', function factory() {
+  return {
+    ...
+    replace: true,
+    templateUrl: 'someUrl'
+    ...
+  }
+});
+
+ +This template is OK as it has one root element `
`. +
+  
Hello World!
+
+ +This template will cause an error since it has multiple roots. (The `` element and the `#text` nodes are the two +top level nodes. +
+  Hello World!
+
diff --git a/src/ng/compile.js b/src/ng/compile.js index 6aebe537752..97f36168489 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -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); @@ -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)); } diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index c1dedd4ab72..c6e955998dc 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -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; diff --git a/test/ng/directive/booleanAttrsSpec.js b/test/ng/directive/booleanAttrsSpec.js index 93e8cc20f7f..02e135edf9c 100644 --- a/test/ng/directive/booleanAttrsSpec.js +++ b/test/ng/directive/booleanAttrsSpec.js @@ -93,7 +93,7 @@ describe('boolean attr directives', function() { expect(function() { $compile('') - }).toThrow('[$compile:selmulti] Binding to the multiple attribute is not supported. ' + + }).toThrow('[$compile:selmulti] Binding to the \'multiple\' attribute is not supported. ' + 'Element: