Skip to content

Commit

Permalink
Add webcomponent.
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamRClark committed May 27, 2021
1 parent c07245d commit 1a87819
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 63 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build": "ng build --prod --output-hashing none",
"test": "ng test",
"test-headless": "ng test --watch=false --browsers=ChromeHeadless",
"lint": "ng lint",
Expand Down
Empty file removed src/app/app.component.css
Empty file.
3 changes: 0 additions & 3 deletions src/app/app.component.html

This file was deleted.

29 changes: 0 additions & 29 deletions src/app/app.component.spec.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/app/app.component.ts

This file was deleted.

25 changes: 16 additions & 9 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { Injector, NgModule } from '@angular/core';
import { createCustomElement } from '@angular/elements';

import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
import { FileBrowseComponent } from './file-browse/file-browse.component';

@NgModule({
declarations: [
AppComponent,
FileBrowseComponent
],
imports: [
BrowserModule,
HttpClientModule
HttpClientModule,
],
providers: [],
bootstrap: [AppComponent]
declarations: [FileBrowseComponent]
})
export class AppModule { }
export class AppModule {

constructor(private injector: Injector) {

}

ngDoBootstrap(){
const fbComp = createCustomElement(FileBrowseComponent, { injector: this.injector });
customElements.define('file-browse', fbComp);
}

}
10 changes: 8 additions & 2 deletions src/app/file-browse/file-browse.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { Component, Injector, OnInit } from '@angular/core';
import { createCustomElement } from '@angular/elements';
import { FileServiceService } from '../services/file-service.service';


@Component({
selector: 'local-file-browse',
templateUrl: './file-browse.component.html',
Expand All @@ -12,7 +14,11 @@ export class FileBrowseComponent implements OnInit {
public selectedFile;
private rootPath;

constructor(private fileService: FileServiceService) {
constructor(injector: Injector, private fileService: FileServiceService) {
// Convert `FileBrowseComponent` to a custom element.
const FileBrowseElement = createCustomElement(FileBrowseComponent, {injector});
// Register the custom element with the browser.
customElements.define('local-file-browse', FileBrowseElement);
}

ngOnInit(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<app-root></app-root>
<file-browse></file-browse>
</body>
</html>
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ if (environment.production) {
enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
platformBrowserDynamic()
.bootstrapModule(AppModule, { ngZone: 'noop' })
.catch(err => console.error(err));

0 comments on commit 1a87819

Please sign in to comment.