Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/paveldymkov/ng-to-parent


https://github.com/paveldymkov/ng-to-parent

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# ng-to-parent

![tests: passing](https://raw.githubusercontent.com/PavelDymkov/ng-to-parent/master/badges/tests.svg)

Send data to parent.

```ts
import { Message } from "ng-to-parent";

// create a message type
export const inputData = new Message();
```

```ts
import { ToParent } from "ng-to-parent";

@Component({
selector: "app-child",
template: `

Click me!
`,
// It's important to provide
// in the component, not to a module
providers: [ToParent], // << !!!
})
export class ChildComponent {
constructor(private toParent: ToParent) {}

send(text: string): void {
this.toParent.send(inputData, void 0);
}
}
```

```ts
import { FromChild } from "ng-to-parent";

@Component({
selector: "app-parent",
template: "",
// It's important to provide
// in the component, not to a module
providers: [FromChild], // << !!!
})
export class ParentComponent {
constructor(fromChild: FromChild) {
fromChild.listen(inputData).subscribe((text) => {
console.log(text);
});
}
}
```