fix(upgrade): fallback to root ng2 injector when element is compiled outside the document (#8684)

Currently downgraded ng2 elements fail inside a ui-router view because they are unable
to require an ng2 Injector via the require attribute of the DDO, because ui-router compiles
its templates before they are inserted in a ui-view. This adds a "fallback" behavior if
a parent injector cannot be found to go to the root ng2 Injector.
This commit is contained in:
Hannah Howard
2016-05-17 15:55:53 -07:00
committed by Miško Hevery
parent 7bb5167239
commit db8290632f
4 changed files with 39 additions and 4 deletions

View File

@ -256,6 +256,37 @@ export function main() {
async.done();
})});
}));
it('should fallback to the root ng2.injector when compiled outside the dom',
inject([AsyncTestCompleter], (async) => {
var adapter: UpgradeAdapter = new UpgradeAdapter();
var ng1Module = angular.module('ng1', []);
ng1Module.directive('ng1', ['$compile', ($compile) => {
return {
link: function($scope, $element, $attrs) {
var compiled = $compile("<ng2></ng2>");
var template = compiled($scope);
$element.append(template);
}
};
}]);
var Ng2 = Component({ selector: 'ng2', template: 'test' })
.Class({
constructor: function() { }
});
ng1Module.directive('ng2', adapter.downgradeNg2Component(Ng2));
var element = html('<ng1></ng1>');
adapter.bootstrap(element, ['ng1'])
.ready((ref) => {
expect(multiTrim(document.body.textContent))
.toEqual('test');
ref.dispose();
async.done();
});
}));
});
describe('upgrade ng1 component', () => {