Skip to content

Instantly share code, notes, and snippets.

View alexzuza's full-sized avatar
🎯
Focusing

Alexey Zuev alexzuza

🎯
Focusing
View GitHub Profile
@alexzuza
alexzuza / di_injectable_new_api_example.ts
Created March 20, 2018 19:05
DI injectable new api example
@Injectable({
providedIn: 'root'
})
export class SomeService {}
@Injectable({
providedIn: 'root',
useClass: MyService,
deps: []
})
@alexzuza
alexzuza / di_injectable_new_api.ts
Last active March 20, 2018 18:47
DI Injectable new API
export interface InjectableDecorator {
(): any;
(options?: {providedIn: Type<any>| 'root' | null}&InjectableProvider): any;
new (): Injectable;
new (options?: {providedIn: Type<any>| 'root' | null}&InjectableProvider): Injectable;
}
export type InjectableProvider = ValueSansProvider | ExistingSansProvider |
StaticClassSansProvider | ConstructorSansProvider | FactorySansProvider | ClassSansProvider;
@alexzuza
alexzuza / di_module_injector_check.ts
Created March 20, 2018 06:27
DI module injector check
startView.root.ngModule.injector.get(depDef.token, notFoundValue);
@alexzuza
alexzuza / di_element_injector_check.ts
Last active March 20, 2018 06:27
DI element injector check
startView.root.injector.get(depDef.token, NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR);
@alexzuza
alexzuza / di_simple_application_with_lazy_loading.ts
Created March 20, 2018 06:21
DI simple application with lazy loading
@Component({
selector: 'child',
template: `
Child
<router-outlet></router-outlet>
`
})
export class ChildComponent {}
...
@NgModule({
@alexzuza
alexzuza / di_router_dynamic_creation.ts
Created March 20, 2018 06:19
DI router dynamic creation
const injector = new OutletInjector(activatedRoute, childContexts, this.location.injector);
this.activated = this.location.createComponent(factory, this.location.length, injector);
@alexzuza
alexzuza / di_simple_router_application.ts
Created March 20, 2018 06:17
DI simple routed application
@Component({
selector: 'my-app',
template: `<router-outlet></router-outlet>`,
})
export class AppComponent {}
...
@NgModule({
imports: [
BrowserModule,
RouterModule.forRoot([
@alexzuza
alexzuza / di_view_parent_element_hierarhy.ts
Last active March 20, 2018 05:15
DI view parent element hierarhy
@Component({
selector: 'my-app',
template: `<my-list></my-list>`
})
export class AppComponent {}
@Component({
selector: 'my-list',
template: `
<div class="container">
@alexzuza
alexzuza / di_embedded_view_parent.ts
Last active March 20, 2018 05:43
DI embedded view parent
@Component({
selector: 'my-list',
template: `
<div class="container">
<grid-list *ngIf="1">
<grid-tile>1</grid-tile>
<grid-tile>2</grid-tile>
<grid-tile>3</grid-tile>
</grid-list>
</div>
@alexzuza
alexzuza / di_view_parent_element.ts
Last active March 19, 2018 21:04
DI view parent element
/**
* for component views, this is the host element.
* for embedded views, this is the index of the parent node
* that contains the view container.
*/
export function viewParentEl(view: ViewData): NodeDef|null {
const parentView = view.parent;
if (parentView) {
return view.parentNodeDef !.parent;
} else {