ngSwitch error when using Angular with Polymer's platform.js loaded #8598
Description
Context: As part of a large AngularJS application, we're trying to bring in a small Polymer Web Component. platform.js
is loaded first in the page, and Angular is manually bootstrapped on a wrapped document node.
It all works fine in latest Chromium (likely because the platform.js polyfills don't do much as most/all? APIs exist natively), but fails with an error in FF 31. I've isolated the error to nested ngSwitch, which result in a slightly weird minimal failing reduced case that you can see at http://jsbin.com/roxif/6/edit
The offending code is the following:
<div ng:switch="3">
<div ng:switch-when="3">
<div>
<div ng:switch="3">
<div ng:switch-when="3">3</div>
</div>
</div>
</div>
</div>
Note that the extra wrapping div
in between the nested ngSwitches is required for the error to occur. Without that extra element, the error disappears.
The following error gets thrown:
Error: node is undefined
compositeLinkFn@https://rawgit.com/angular/bower-angular/v1.2.16/angular.js:5989:13
nodeLinkFn@https://rawgit.com/angular/bower-angular/v1.2.16/angular.js:6573:9
compositeLinkFn@https://rawgit.com/angular/bower-angular/v1.2.16/angular.js:5983:1
nodeLinkFn@https://rawgit.com/angular/bower-angular/v1.2.16/angular.js:6573:9
compositeLinkFn@https://rawgit.com/angular/bower-angular/v1.2.16/angular.js:5986:15
publicLinkFn@https://rawgit.com/angular/bower-angular/v1.2.16/angular.js:5891:30
ngViewFillContentFactory/<.link@https://rawgit.com/angular/bower-angular-route/v1.2.16/angular-route.js:921:7
nodeLinkFn@https://rawgit.com/angular/bower-angular/v1.2.16/angular.js:6580:1
compositeLinkFn@https://rawgit.com/angular/bower-angular/v1.2.16/angular.js:5986:15
publicLinkFn@https://rawgit.com/angular/bower-angular/v1.2.16/angular.js:5891:30
boundTranscludeFn@https://rawgit.com/angular/bower-angular/v1.2.16/angular.js:6005:13
controllersBoundTransclude@https://rawgit.com/angular/bower-angular/v1.2.16/angular.js:6600:11
update@https://rawgit.com/angular/bower-angular-route/v1.2.16/angular-route.js:871:17
$RootScopeProvider/this.$get</Scope.prototype.$broadcast@https://rawgit.com/angular/bower-angular/v1.2.16/angular.js:12691:15
updateRoute/<@https://rawgit.com/angular/bower-angular-route/v1.2.16/angular-route.js:552:15
etc...
It looks like the error maps to the last line of the following function (node.childNodes
where node
is undefined
):
function compositeLinkFn(scope, nodeList, $rootElement, boundTranscludeFn) {
var nodeLinkFn, childLinkFn, node, $node, childScope, childTranscludeFn, i, ii, n;
// copy nodeList so that linking doesn't break due to live list updates.
var nodeListLength = nodeList.length,
stableNodeList = new Array(nodeListLength);
for (i = 0; i < nodeListLength; i++) {
stableNodeList[i] = nodeList[i];
}
for(i = 0, n = 0, ii = linkFns.length; i < ii; n++) {
node = stableNodeList[n];
nodeLinkFn = linkFns[i++];
childLinkFn = linkFns[i++];
$node = jqLite(node);
if (nodeLinkFn) {
if (nodeLinkFn.scope) {
childScope = scope.$new();
$node.data('$scope', childScope);
} else {
childScope = scope;
}
childTranscludeFn = nodeLinkFn.transclude;
if (childTranscludeFn || (!boundTranscludeFn && transcludeFn)) {
nodeLinkFn(childLinkFn, childScope, node, $rootElement,
createBoundTranscludeFn(scope, childTranscludeFn || transcludeFn)
);
} else {
nodeLinkFn(childLinkFn, childScope, node, $rootElement, boundTranscludeFn);
}
} else if (childLinkFn) {
childLinkFn(scope, node.childNodes, undefined, boundTranscludeFn);
}
}
Note that this fails even with the latest stable Angular version (1.2.22) as per this other example and also with the latest unstable Angular version (1.3.0-beta.18) as per this example.
It seems likely that this is a broken edge case of the wrapping platform.js does to polyfill Shadow DOM in FF?
Any hints as to where this error comes from and how to solve it?
I will cross-file this issue in the Polymer bug tracker as they may also be interested to know about this.
Thanks in advance.