Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output for <ngt-canvas /> #71

Closed
dolanmiu opened this issue Jan 16, 2025 · 4 comments
Closed

Output for <ngt-canvas /> #71

dolanmiu opened this issue Jan 16, 2025 · 4 comments

Comments

@dolanmiu
Copy link

I am creating a component in a library which uses angular-three

Somewhere in the Scene Graph, it emits output. I want this to be bubbled up out of the component, into the host app.

I added an output on my SceneGraph, but I can't see it in <ngt-canvas />

export class SceneGraph {
  protected readonly Math = Math;
  pointsOfInterest = output<Vector3>();
}
@Component({
  selector: 'lib-three-d-hero',
  standalone: true,
  imports: [NgtCanvas],
  template: ` <ngt-canvas [sceneGraph]="sceneGraph" (pointsOfInterest)="pointsOfInterest.emit($event)" /> `,
  styles: `
    :host {
      display: block;
      height: 100dvh;
    }
  `,
})

How can I make this work?

@ldu0009
Copy link

ldu0009 commented Jan 17, 2025

The standard Angular component hierarchy differs in this case, as the SceneGraph is not part of Angular’s standard DOM tree or component tree. As a result, it’s not possible to propagate @Output events directly to the parent component (e.g., <ngt-canvas>).

If you need to pass data or events, the recommended approach would be to use a service to handle the communication.

@nartc
Copy link
Member

nartc commented Jan 18, 2025

Hi @dolanmiu, @ldu0009 is correct in this case.

That said, I'm happy to push a patch version to expose the ComponentRef for SceneGraph that is created.

@nartc
Copy link
Member

nartc commented Jan 18, 2025

3.7.0 now adds a (rendered) output on <ngt-canvas />. This output emits the ComponentRef that is created by rendering the [sceneGraph]

@Component({
  template: `
    <ngt-canvas [sceneGraph]="sceneGraph" (rendered)="onRendered($event)" />
  `
})
export class MyCmp {
  sceneGraph = SceneGraph;

  onRendered(ev: ComponentRef<SceneGraph>) {
    // now you can do anything with the ComponentRef
    // ev.setInput()
    // ev.instance.someOutput.subscribe()
  }
}

@nartc nartc closed this as completed Jan 18, 2025
@ldu0009
Copy link

ldu0009 commented Jan 19, 2025

@nartc Wow! This opens up endless possibilities. I’m so excited to see what we can do with it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants