Skip to content

Commit

Permalink
Update doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamRClark committed May 28, 2021
1 parent 6ddf27c commit 2510194
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# NgxFileSelect

This is a local file browse web component that you can integrate into your website.
<img src="./doc/FileBrowseComponent.png" width="600">

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 10.1.1.

## Development server
Expand All @@ -25,3 +28,19 @@ Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protrac
## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).


## Custom Components

The file-browse custom component is exported from this library. The goal of this component is to select files from your local filesystem, and return the result to anyone who is listening. Anywhere in your code, you can add the following text to listen:

```javascript
window.addEventListener('fselect', (event) => {
alert('File selected: ' + JSON.stringify(event.detail))
})
```
And add the following tag to display the listener:

```html
<file-browse></file-browse>
```
Binary file added doc/FileBrowseComponent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions src/app/file-browse/file-browse.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Injector, OnInit } from '@angular/core';
import { Component, EventEmitter, Output, Injector, OnInit } from '@angular/core';
import { createCustomElement } from '@angular/elements';
import { FileServiceService } from '../services/file-service.service';

Expand Down Expand Up @@ -46,12 +46,14 @@ export class FileBrowseComponent implements OnInit {
// Compute the full path.
if (this.selectedFile) {
console.log('file selected: ' + this.rootPath + this.getCurrentPath() + '/' + this.selectedFile.name);
let event = new CustomEvent("file-select", {
// Dispatch using window custom event so we can listen from anywhere.
let event = new CustomEvent("fselect", {
detail: {
path: this.rootPath + this.getCurrentPath() + '/' + this.selectedFile.name
}
});
window.dispatchEvent(event);

}
}

Expand Down

0 comments on commit 2510194

Please sign in to comment.