2016-06-28 09:54:42 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import {LowerCasePipe, NgIf} from '@angular/common';
|
2016-07-07 11:57:11 -07:00
|
|
|
import {ANALYZE_FOR_PRECOMPILE, AppModule, Component, ComponentFactoryResolver, Directive, Inject, Injectable, Input, OpaqueToken, Pipe} from '@angular/core';
|
2016-06-30 13:07:17 -07:00
|
|
|
import {BrowserModule} from '@angular/platform-browser';
|
2016-06-28 09:54:42 -07:00
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class SomeService {
|
|
|
|
|
public prop = 'someValue';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class NestedService {
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-07 11:57:11 -07:00
|
|
|
@Directive({selector: '[someDir]', host: {'[title]': 'someDir'}})
|
|
|
|
|
export class SomeDirective {
|
|
|
|
|
@Input()
|
|
|
|
|
someDir: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Pipe({name: 'somePipe'})
|
|
|
|
|
export class SomePipe {
|
|
|
|
|
transform(value: string): any { return `transformed ${value}`; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Component({selector: 'cmp', template: `<div [someDir]="'someValue' | somePipe"></div>`})
|
2016-06-28 09:54:42 -07:00
|
|
|
export class SomeComp {
|
|
|
|
|
constructor() {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Component({selector: 'parent', template: `<cmp></cmp>`, directives: [SomeComp]})
|
|
|
|
|
export class ParentComp {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AppModule({providers: [NestedService]})
|
|
|
|
|
export class NestedModule {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AppModule({
|
2016-07-07 11:57:11 -07:00
|
|
|
directives: [SomeDirective],
|
|
|
|
|
pipes: [SomePipe],
|
2016-06-28 09:54:42 -07:00
|
|
|
providers: [SomeService],
|
|
|
|
|
precompile: [SomeComp],
|
2016-06-30 13:07:17 -07:00
|
|
|
modules: [NestedModule, BrowserModule]
|
2016-06-28 09:54:42 -07:00
|
|
|
})
|
|
|
|
|
export class SomeModule {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AppModule({
|
2016-07-07 11:57:11 -07:00
|
|
|
directives: [SomeDirective],
|
|
|
|
|
pipes: [SomePipe],
|
2016-06-28 09:54:42 -07:00
|
|
|
precompile: [ParentComp],
|
2016-06-30 13:07:17 -07:00
|
|
|
modules: [BrowserModule]
|
2016-06-28 09:54:42 -07:00
|
|
|
})
|
|
|
|
|
export class SomeModuleUsingParentComp {
|
|
|
|
|
}
|
2016-07-07 10:05:55 -07:00
|
|
|
|
|
|
|
|
export const SOME_TOKEN = new OpaqueToken('someToken');
|
|
|
|
|
|
|
|
|
|
export function provideValueWithPrecompile(value: any) {
|
|
|
|
|
return [
|
|
|
|
|
{provide: SOME_TOKEN, useValue: value},
|
|
|
|
|
{provide: ANALYZE_FOR_PRECOMPILE, useValue: value, multi: true},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AppModule({providers: [provideValueWithPrecompile([{a: 'b', component: SomeComp}])]})
|
|
|
|
|
export class SomeModuleWithAnalyzePrecompileProvider {
|
|
|
|
|
constructor(@Inject(SOME_TOKEN) public providedValue: any) {}
|
|
|
|
|
}
|