parent
84c3124292
commit
19c1bd7375
|
@ -7,7 +7,14 @@ declare namespace angular {
|
||||||
run(a: any);
|
run(a: any);
|
||||||
}
|
}
|
||||||
interface ICompileService {
|
interface ICompileService {
|
||||||
(element: Element): (IScope) => void;
|
(element: Element, transclude?: Function): ILinkFn;
|
||||||
|
}
|
||||||
|
interface ILinkFn {
|
||||||
|
(scope: IScope, cloneAttachFn?: Function, options?: ILinkFnOptions): void
|
||||||
|
}
|
||||||
|
interface ILinkFnOptions {
|
||||||
|
parentBoundTranscludeFn?: Function, transcludeControllers?: {[key: string]: any},
|
||||||
|
futureParentElement?: Node
|
||||||
}
|
}
|
||||||
interface IRootScopeService {
|
interface IRootScopeService {
|
||||||
$new(): IScope;
|
$new(): IScope;
|
||||||
|
|
|
@ -112,8 +112,16 @@ class Ng1ComponentFacade implements OnChanges, DoCheck {
|
||||||
private inputs: string[], private outputs: string[], private propOuts: string[],
|
private inputs: string[], private outputs: string[], private propOuts: string[],
|
||||||
private checkProperties: string[], private propertyMap: {[key: string]: string}) {
|
private checkProperties: string[], private propertyMap: {[key: string]: string}) {
|
||||||
var chailTail = scope.$$childTail; // remember where the next scope is inserted
|
var chailTail = scope.$$childTail; // remember where the next scope is inserted
|
||||||
compile(elementRef.nativeElement)(scope);
|
var element: Element = elementRef.nativeElement;
|
||||||
|
var childNodes: Node[] = [];
|
||||||
|
var childNode;
|
||||||
|
while (childNode = element.firstChild) {
|
||||||
|
element.removeChild(childNode);
|
||||||
|
childNodes.push(childNode);
|
||||||
|
}
|
||||||
|
element.appendChild(element.ownerDocument.createElement('ng-transclude'));
|
||||||
|
compile(element)(scope, null,
|
||||||
|
{parentBoundTranscludeFn: (scope, cloneAttach) => cloneAttach(childNodes)});
|
||||||
// If we are first scope take it, otherwise take the next one in list.
|
// If we are first scope take it, otherwise take the next one in list.
|
||||||
this.componentScope = chailTail ? chailTail.$$nextSibling : scope.$$childHead;
|
this.componentScope = chailTail ? chailTail.$$nextSibling : scope.$$childHead;
|
||||||
|
|
||||||
|
|
|
@ -34,24 +34,26 @@ export function main() {
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should instantiate ng1 in ng2 template', inject([AsyncTestCompleter], (async) => {
|
it('should instantiate ng1 in ng2 template and project content',
|
||||||
var upgradeModule: UpgradeModule = createUpgradeModule();
|
inject([AsyncTestCompleter], (async) => {
|
||||||
|
var upgrMod: UpgradeModule = createUpgradeModule();
|
||||||
|
|
||||||
var Ng2 = Component({selector: 'ng2-1'})
|
var Ng2 = Component({selector: 'ng2-1'})
|
||||||
.View({
|
.View({
|
||||||
template: `{{ 'ng2(' }}<ng1></ng1>{{ ')' }}`,
|
template: `{{ 'ng2(' }}<ng1>{{'transclude'}}</ng1>{{ ')' }}`,
|
||||||
directives: [upgradeModule.exportAsNg2Component('ng1')]
|
directives: [upgrMod.exportAsNg2Component('ng1')]
|
||||||
})
|
})
|
||||||
.Class({constructor: function() {}});
|
.Class({constructor: function() {}});
|
||||||
|
|
||||||
upgradeModule.ng1Module.directive('ng1',
|
upgrMod.ng1Module.directive('ng1', () => {
|
||||||
() => { return {template: 'ng1 {{ "WORKS" }}!'}; });
|
return {transclude: true, template: '{{ "ng1" }}(<ng-transclude></ng-transclude>)'};
|
||||||
upgradeModule.importNg2Component(Ng2);
|
});
|
||||||
|
upgrMod.importNg2Component(Ng2);
|
||||||
|
|
||||||
var element = html("<div>{{'ng1('}}<ng2-1></ng2-1>{{')'}}</div>");
|
var element = html("<div>{{'ng1('}}<ng2-1></ng2-1>{{')'}}</div>");
|
||||||
|
|
||||||
upgradeModule.bootstrap(element).ready(() => {
|
upgrMod.bootstrap(element).ready(() => {
|
||||||
expect(document.body.textContent).toEqual("ng1(ng2(ng1 WORKS!))");
|
expect(document.body.textContent).toEqual("ng1(ng2(ng1(transclude)))");
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in New Issue