├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── browserslist ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.scss │ ├── app.component.ts │ ├── app.module.ts │ ├── bar │ │ ├── bar.component.html │ │ ├── bar.component.scss │ │ ├── bar.component.spec.ts │ │ └── bar.component.ts │ ├── dashboard │ │ ├── dashboard.module.ts │ │ ├── dashboard.service.ts │ │ ├── dashboard │ │ │ ├── dashboard.component.html │ │ │ └── dashboard.component.ts │ │ └── widgets │ │ │ ├── bar │ │ │ ├── bar.component.html │ │ │ ├── bar.component.ts │ │ │ └── bar.service.ts │ │ │ └── funnel │ │ │ ├── funnel.component.html │ │ │ └── funnel.component.ts │ ├── foo │ │ ├── foo.component.html │ │ ├── foo.component.scss │ │ ├── foo.component.spec.ts │ │ └── foo.component.ts │ ├── home │ │ ├── home.component.html │ │ └── home.component.ts │ └── lazy-comp.directive.ts ├── assets │ └── .gitkeep ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.scss └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "exploreivy": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "app", 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "vendorSourceMap": true, 21 | "evalSourceMap": false, 22 | "outputPath": "dist/exploreivy", 23 | "index": "src/index.html", 24 | "main": "src/main.ts", 25 | "polyfills": "src/polyfills.ts", 26 | "tsConfig": "tsconfig.app.json", 27 | "aot": true, 28 | "assets": [ 29 | "src/favicon.ico", 30 | "src/assets" 31 | ], 32 | "styles": [ 33 | "src/styles.scss" 34 | ], 35 | "scripts": [] 36 | }, 37 | "configurations": { 38 | "production": { 39 | "fileReplacements": [ 40 | { 41 | "replace": "src/environments/environment.ts", 42 | "with": "src/environments/environment.prod.ts" 43 | } 44 | ], 45 | "optimization": true, 46 | "outputHashing": "all", 47 | "sourceMap": false, 48 | "extractCss": true, 49 | "namedChunks": false, 50 | "extractLicenses": true, 51 | "vendorChunk": false, 52 | "buildOptimizer": true, 53 | "budgets": [ 54 | { 55 | "type": "initial", 56 | "maximumWarning": "2mb", 57 | "maximumError": "5mb" 58 | }, 59 | { 60 | "type": "anyComponentStyle", 61 | "maximumWarning": "6kb", 62 | "maximumError": "10kb" 63 | } 64 | ] 65 | } 66 | } 67 | }, 68 | "serve": { 69 | "builder": "@angular-devkit/build-angular:dev-server", 70 | "options": { 71 | "browserTarget": "exploreivy:build" 72 | }, 73 | "configurations": { 74 | "production": { 75 | "browserTarget": "exploreivy:build:production" 76 | } 77 | } 78 | }, 79 | "extract-i18n": { 80 | "builder": "@angular-devkit/build-angular:extract-i18n", 81 | "options": { 82 | "browserTarget": "exploreivy:build" 83 | } 84 | }, 85 | "test": { 86 | "builder": "@angular-devkit/build-angular:karma", 87 | "options": { 88 | "main": "src/test.ts", 89 | "polyfills": "src/polyfills.ts", 90 | "tsConfig": "tsconfig.spec.json", 91 | "karmaConfig": "karma.conf.js", 92 | "assets": [ 93 | "src/favicon.ico", 94 | "src/assets" 95 | ], 96 | "styles": [ 97 | "src/styles.scss" 98 | ], 99 | "scripts": [] 100 | } 101 | }, 102 | "lint": { 103 | "builder": "@angular-devkit/build-angular:tslint", 104 | "options": { 105 | "tsConfig": [ 106 | "tsconfig.app.json", 107 | "tsconfig.spec.json", 108 | "e2e/tsconfig.json" 109 | ], 110 | "exclude": [ 111 | "**/node_modules/**" 112 | ] 113 | } 114 | }, 115 | "e2e": { 116 | "builder": "@angular-devkit/build-angular:protractor", 117 | "options": { 118 | "protractorConfig": "e2e/protractor.conf.js", 119 | "devServerTarget": "exploreivy:serve" 120 | }, 121 | "configurations": { 122 | "production": { 123 | "devServerTarget": "exploreivy:serve:production" 124 | } 125 | } 126 | } 127 | } 128 | }}, 129 | "defaultProject": "exploreivy" 130 | } 131 | -------------------------------------------------------------------------------- /browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('exploreivy app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo(): Promise { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/exploreivy'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~9.0.0", 15 | "@angular/common": "~9.0.0", 16 | "@angular/compiler": "~9.0.0", 17 | "@angular/core": "~9.0.0", 18 | "@angular/forms": "~9.0.0", 19 | "@angular/platform-browser": "~9.0.0", 20 | "@angular/platform-browser-dynamic": "~9.0.0", 21 | "@angular/router": "~9.0.0", 22 | "rxjs": "~6.5.4", 23 | "tslib": "^1.10.0", 24 | "zone.js": "~0.10.2" 25 | }, 26 | "devDependencies": { 27 | "@angular-devkit/build-angular": "~0.900.1", 28 | "@angular/cli": "~9.0.1", 29 | "@angular/compiler-cli": "~9.0.0", 30 | "@angular/language-service": "~9.0.0", 31 | "@types/node": "^12.11.1", 32 | "@types/jasmine": "~3.5.0", 33 | "@types/jasminewd2": "~2.0.3", 34 | "codelyzer": "^5.1.2", 35 | "jasmine-core": "~3.5.0", 36 | "jasmine-spec-reporter": "~4.2.1", 37 | "karma": "~4.3.0", 38 | "karma-chrome-launcher": "~3.1.0", 39 | "karma-coverage-istanbul-reporter": "~2.1.0", 40 | "karma-jasmine": "~2.0.1", 41 | "karma-jasmine-html-reporter": "^1.4.2", 42 | "protractor": "~5.4.3", 43 | "ts-node": "~8.3.0", 44 | "tslint": "~5.18.0", 45 | "typescript": "~3.7.5" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { HomeComponent } from './home/home.component'; 4 | 5 | const routes: Routes = [{ 6 | path: '', 7 | pathMatch: 'full', 8 | component: HomeComponent 9 | }, { 10 | path: 'dashboard', 11 | loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule) 12 | }]; 13 | 14 | @NgModule({ 15 | imports: [RouterModule.forRoot(routes)], 16 | exports: [RouterModule] 17 | }) 18 | export class AppRoutingModule { 19 | } 20 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NetanelBasal/ivy-lazy-components/da6d601e616ca8082ed9372c34b528b1a4a1a7ce/src/app/app.component.scss -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, ComponentFactoryResolver, ComponentRef, Injector, Type, ViewChild, ViewContainerRef } from '@angular/core'; 2 | import { FooComponent } from './foo/foo.component'; 3 | import { BarComponent } from './bar/bar.component'; 4 | 5 | @Component({ 6 | selector: 'app-root', 7 | templateUrl: './app.component.html', 8 | styleUrls: ['./app.component.scss'] 9 | }) 10 | export class AppComponent { 11 | @ViewChild('vcr', { read: ViewContainerRef }) vcr: ViewContainerRef; 12 | title = 'exploreivy'; 13 | show = false; 14 | foo: Promise>; 15 | fooInjector: Injector; 16 | barRef: ComponentRef; 17 | 18 | bar; 19 | inputs = { 20 | title: 'Hello' 21 | } 22 | outputs = { 23 | titleChanges: (v) => { 24 | console.log(v); 25 | } 26 | } 27 | constructor(private resolver: ComponentFactoryResolver, 28 | private injector: Injector) { 29 | } 30 | 31 | updateInputs() { 32 | this.inputs = { 33 | title: 'Changed' 34 | } 35 | } 36 | 37 | t() { 38 | this.bar = import(`./bar/bar.component`).then(({ BarComponent}) => BarComponent); 39 | } 40 | 41 | async loadBar() { 42 | if (!this.barRef) { 43 | const { BarComponent } = await import(`./bar/bar.component`); 44 | const factory = this.resolver.resolveComponentFactory(BarComponent); 45 | this.barRef = this.vcr.createComponent(factory); 46 | this.barRef.instance.title = 'Changed'; 47 | this.barRef.instance.titleChanges.subscribe(console.log); 48 | } 49 | } 50 | 51 | loadFoo() { 52 | if (!this.foo) { 53 | this.fooInjector = Injector.create({ 54 | providers: [{ 55 | provide: 'fooData', 56 | useValue: { id: 1 } 57 | }], 58 | parent: this.injector 59 | }); 60 | this.foo = import(/* webpackChunkName: 'foo' */`./foo/foo.component`).then(({ FooComponent }) => FooComponent); 61 | 62 | // this.foo = import(/* webpackPrefetch: true */`./foo/foo.component`).then(({ FooComponent }) => FooComponent); 63 | } 64 | } 65 | 66 | ngOnDestroy() { 67 | this.barRef = null; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { AppRoutingModule } from './app-routing.module'; 5 | import { AppComponent } from './app.component'; 6 | import { HomeComponent } from './home/home.component'; 7 | import { LazyCompDirective } from './lazy-comp.directive'; 8 | 9 | @NgModule({ 10 | declarations: [ 11 | AppComponent, 12 | HomeComponent, 13 | LazyCompDirective, 14 | ], 15 | imports: [ 16 | BrowserModule, 17 | AppRoutingModule, 18 | ], 19 | providers: [], 20 | bootstrap: [AppComponent] 21 | }) 22 | export class AppModule { } 23 | -------------------------------------------------------------------------------- /src/app/bar/bar.component.html: -------------------------------------------------------------------------------- 1 |

{{ title }}

2 | -------------------------------------------------------------------------------- /src/app/bar/bar.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NetanelBasal/ivy-lazy-components/da6d601e616ca8082ed9372c34b528b1a4a1a7ce/src/app/bar/bar.component.scss -------------------------------------------------------------------------------- /src/app/bar/bar.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { BarComponent } from './bar.component'; 4 | 5 | describe('BarComponent', () => { 6 | let component: BarComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ BarComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(BarComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/bar/bar.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-bar', 5 | templateUrl: './bar.component.html', 6 | styleUrls: ['./bar.component.scss'] 7 | }) 8 | export class BarComponent implements OnInit { 9 | title = 'Default'; 10 | titleChanges = new EventEmitter(); 11 | 12 | constructor() { 13 | } 14 | 15 | ngOnInit(): void { 16 | console.log('ngOnInit'); 17 | } 18 | 19 | ngOnDestroy() { 20 | console.log('ngOnDestroy'); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/app/dashboard/dashboard.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { DashboardComponent } from './dashboard/dashboard.component'; 4 | import { RouterModule } from '@angular/router'; 5 | 6 | @NgModule({ 7 | declarations: [DashboardComponent], 8 | imports: [ 9 | CommonModule, 10 | RouterModule.forChild([{ 11 | path: '', 12 | component: DashboardComponent 13 | }]) 14 | ] 15 | }) 16 | export class DashboardModule { 17 | } 18 | -------------------------------------------------------------------------------- /src/app/dashboard/dashboard.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { timer } from 'rxjs'; 3 | import { mapTo } from 'rxjs/operators'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class DashboardService { 9 | 10 | constructor() { } 11 | 12 | getWidgets() { 13 | return timer(300).pipe(mapTo([{ 14 | type: 'bar' 15 | }, { 16 | type: 'funnel' 17 | }])) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/app/dashboard/dashboard/dashboard.component.html: -------------------------------------------------------------------------------- 1 |

Widgets

2 | 3 | -------------------------------------------------------------------------------- /src/app/dashboard/dashboard/dashboard.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { DashboardService } from '../dashboard.service'; 3 | import { mergeMap } from 'rxjs/operators'; 4 | import { Observable } from 'rxjs'; 5 | 6 | @Component({ 7 | selector: 'app-dashboard', 8 | templateUrl: './dashboard.component.html' 9 | }) 10 | export class DashboardComponent implements OnInit { 11 | widgets$: Observable; 12 | 13 | constructor(private dashboardService: DashboardService) { 14 | } 15 | 16 | ngOnInit() { 17 | this.widgets$ = this.dashboardService.getWidgets().pipe(mergeMap((widgets) => { 18 | return Promise.all(widgets.map(widget => { 19 | return import(`../widgets/${widget.type}/${widget.type}.component`); 20 | })) 21 | })); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/app/dashboard/widgets/bar/bar.component.html: -------------------------------------------------------------------------------- 1 |

bar works!

2 | -------------------------------------------------------------------------------- /src/app/dashboard/widgets/bar/bar.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { BarService } from './bar.service'; 3 | 4 | @Component({ 5 | selector: 'app-bar', 6 | templateUrl: './bar.component.html' 7 | }) 8 | export default class BarComponent implements OnInit { 9 | 10 | constructor(private barService: BarService) { 11 | } 12 | 13 | ngOnInit(): void { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/app/dashboard/widgets/bar/bar.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | 3 | @Injectable({ 4 | providedIn: 'root' 5 | }) 6 | export class BarService { 7 | 8 | constructor() { 9 | console.log('BarService'); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/app/dashboard/widgets/funnel/funnel.component.html: -------------------------------------------------------------------------------- 1 |

funnel works!

2 | -------------------------------------------------------------------------------- /src/app/dashboard/widgets/funnel/funnel.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-funnel', 5 | templateUrl: './funnel.component.html' 6 | }) 7 | export default class FunnelComponent implements OnInit { 8 | 9 | constructor() { } 10 | 11 | ngOnInit(): void { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/app/foo/foo.component.html: -------------------------------------------------------------------------------- 1 |

Foo works!

2 | {{ control.value }} 3 | 4 | -------------------------------------------------------------------------------- /src/app/foo/foo.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NetanelBasal/ivy-lazy-components/da6d601e616ca8082ed9372c34b528b1a4a1a7ce/src/app/foo/foo.component.scss -------------------------------------------------------------------------------- /src/app/foo/foo.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { FooComponent } from './foo.component'; 4 | 5 | describe('FooComponent', () => { 6 | let component: FooComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ FooComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(FooComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/foo/foo.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Inject, NgModule, OnInit } from '@angular/core'; 2 | import { FormControl, ReactiveFormsModule } from '@angular/forms'; 3 | 4 | @Component({ 5 | selector: 'app-foo', 6 | templateUrl: './foo.component.html', 7 | styleUrls: ['./foo.component.scss'] 8 | }) 9 | export class FooComponent implements OnInit { 10 | control = new FormControl(); 11 | 12 | constructor(@Inject('fooData') data) { 13 | console.log(data); 14 | } 15 | 16 | ngOnInit(): void { 17 | } 18 | 19 | } 20 | 21 | @NgModule({ 22 | imports: [ReactiveFormsModule], 23 | declarations: [FooComponent] 24 | }) 25 | class FooModule { 26 | } 27 | -------------------------------------------------------------------------------- /src/app/home/home.component.html: -------------------------------------------------------------------------------- 1 |

home works!

2 | -------------------------------------------------------------------------------- /src/app/home/home.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-home', 5 | templateUrl: './home.component.html' 6 | }) 7 | export class HomeComponent implements OnInit { 8 | 9 | constructor() { } 10 | 11 | ngOnInit(): void { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/app/lazy-comp.directive.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFactoryResolver, ComponentRef, Directive, EventEmitter, Input, Type, ViewContainerRef } from '@angular/core'; 2 | import { Subscription } from 'rxjs'; 3 | 4 | @Directive({ 5 | selector: '[lazyComp]' 6 | }) 7 | export class LazyCompDirective { 8 | private _inputs; 9 | private _outputs; 10 | private subscription = new Subscription(); 11 | 12 | @Input('lazyComp') set comp(type: Type) { 13 | // TODO: Support components replacment 14 | if (type) { 15 | const factory = this.resolver.resolveComponentFactory(type); 16 | this.compRef = this.vcr.createComponent(factory); 17 | this.refreshInputs(this._inputs); 18 | Object.keys(this._outputs).forEach(output => { 19 | this.subscription.add((this.compRef.instance[output] as EventEmitter).subscribe(this._outputs[output])); 20 | }); 21 | } 22 | } 23 | 24 | @Input() set inputs(data) { 25 | if (this.compRef) { 26 | this.refreshInputs(data); 27 | this.compRef.hostView.detectChanges(); 28 | } else { 29 | this._inputs = data; 30 | } 31 | } 32 | 33 | @Input() set outputs(data) { 34 | this._outputs = data; 35 | } 36 | 37 | private compRef: ComponentRef; 38 | 39 | constructor(private vcr: ViewContainerRef, private resolver: ComponentFactoryResolver) { 40 | } 41 | 42 | private refreshInputs(inputs) { 43 | Object.keys(inputs).forEach(inputName => this.compRef.instance[inputName] = inputs[inputName]); 44 | } 45 | 46 | ngOnDestroy() { 47 | this.compRef && this.compRef.destroy(); 48 | this.compRef = null; 49 | this.subscription.unsubscribe(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NetanelBasal/ivy-lazy-components/da6d601e616ca8082ed9372c34b528b1a4a1a7ce/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NetanelBasal/ivy-lazy-components/da6d601e616ca8082ed9372c34b528b1a4a1a7ce/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Exploreivy 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/app/dashboard/widgets/**/*.component.ts", 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | }, 22 | "angularCompilerOptions": { 23 | "fullTemplateTypeCheck": true, 24 | "strictInjectionParameters": true 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | {} 2 | --------------------------------------------------------------------------------