fix(compiler_cli): allow to use builtin directives like NgIf, …

Related to #8448
Closes #8454
This commit is contained in:
Tobias Bosch
2016-05-03 17:31:40 -07:00
parent 0297398f5e
commit edec158dd8
14 changed files with 130 additions and 20 deletions

View File

@ -1,3 +1,3 @@
<div>{{ctxProp}}</div>
<form><input type="button" [(ngModel)]="ctxProp"/></form>
<my-comp></my-comp>
<my-comp *ngIf="ctxBool"></my-comp>

View File

@ -1,5 +1,5 @@
import {Component, Inject} from '@angular/core';
import {FORM_DIRECTIVES} from '@angular/common';
import {FORM_DIRECTIVES, NgIf} from '@angular/common';
import {MyComp} from './a/multiple_components';
@Component({
@ -7,9 +7,10 @@ import {MyComp} from './a/multiple_components';
templateUrl: './basic.html',
styles: ['.red { color: red }'],
styleUrls: ['./basic.css'],
directives: [MyComp, FORM_DIRECTIVES]
directives: [MyComp, FORM_DIRECTIVES, NgIf]
})
export class Basic {
ctxProp: string;
constructor() { this.ctxProp = 'initiaValue'; }
ctxBool: boolean;
constructor() { this.ctxProp = 'initialValue'; }
}

View File

@ -1,5 +1,9 @@
import * as fs from 'fs';
import * as path from 'path';
import {BasicNgFactory} from '../src/basic.ngfactory';
import {MyComp} from '../src/a/multiple_components';
import {ReflectiveInjector, DebugElement, getDebugNode} from '@angular/core';
import {browserPlatform, BROWSER_APP_STATIC_PROVIDERS} from '@angular/platform-browser';
describe("template codegen output", () => {
const outDir = path.join('dist', 'all', '@angular', 'compiler_cli', 'integrationtest', 'src');
@ -23,4 +27,17 @@ describe("template codegen output", () => {
expect(fs.existsSync(dtsOutput)).toBeTruthy();
expect(fs.readFileSync(dtsOutput, {encoding: 'utf-8'})).toContain('Basic');
});
it("should be able to create the basic component and trigger an ngIf", () => {
const appInjector = ReflectiveInjector.resolveAndCreate(BROWSER_APP_STATIC_PROVIDERS,
browserPlatform().injector);
var comp = BasicNgFactory.create(appInjector);
var debugElement = <DebugElement>getDebugNode(comp.location.nativeElement);
expect(debugElement.children.length).toBe(2);
comp.instance.ctxBool = true;
comp.changeDetectorRef.detectChanges();
expect(debugElement.children.length).toBe(3);
expect(debugElement.children[2].injector.get(MyComp)).toBeTruthy();
});
});