This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Directive({ | |
standalone: true, | |
selector: 'img[rawSrc]', | |
}) | |
export class NgOptimizedImage implements OnInit, OnChanges, OnDestroy { | |
private imageLoader = inject(IMAGE_LOADER); | |
private renderer = inject(Renderer2); | |
private imgElement: HTMLImageElement = inject(ElementRef).nativeElement; | |
private injector = inject(Injector); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class AppComponent { | |
private foo = inject(FOO) // typed as string | |
private bar = inject(BAR, { optional: true }) // typed as string | null | |
private http = inject(HttpClient) // typed as HttpClient | |
private todosService = inject(TodosService) // typed as TodosService | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class AppComponent { | |
private foo = inject(FOO) | |
private bar = inject(BAR, { optional: true }) | |
private http = inject(HttpClient); | |
private todosService = inject(TodosService); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class AppComponent { | |
constructor( | |
@Inject(FOO) private foo: string, | |
@Optional() @Inject(BAR) private bar: string | null, | |
private http: HttpClient, | |
private todosService: TodosService | |
) { } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, ElementRef, inject } from '@angular/core'; | |
import { App } from '@myorg/app-name'; | |
import { NgReact } from '@myorg/ng-react'; | |
@Component({ | |
standalone: true, | |
template: `` | |
}) | |
export class TodosPageComponent { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import NxWelcome from './nx-welcome'; | |
export function App() { | |
return ( | |
<> | |
<NxWelcome title="react-platform" /> | |
... | |
</> | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... THE CONTEXT CODE IS ABOVE ... | |
@Injectable({ providedIn: 'root' }) | |
export class NgReact { | |
injector = inject(Injector); | |
createRoot(host: HTMLElement) { | |
return createRoot(host); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injector } from '@angular/core'; | |
import { PropsWithChildren, createContext, useContext } from 'react'; | |
import { createRoot, Root } from 'react-dom/client' | |
const InjectorCtx = createContext<Injector | null>(null) | |
export function NgContext(props: PropsWithChildren<{ injector: Injector }>) { | |
return createElement(InjectorCtx.Provider, { | |
children: props.children, | |
value: props.injector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CommonModule } from '@angular/common'; | |
import { Component, ElementRef, OnDestroy, OnInit } from '@angular/core'; | |
import type { ComponentProps } from 'react'; | |
@Component({ | |
standalone: true, | |
imports: [CommonModule, LazyReactComponentDirective], | |
template: ` | |
<h1>Todos page</h1> | |
<button (click)="showSelect = true">Show React Component</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, ElementRef, Input } from '@angular/core'; | |
import type { ComponentProps, ElementType } from 'react'; | |
import type { Root } from 'react-dom/client'; | |
@Directive({ | |
selector: '[lazyReactComponent]', | |
standalone: true | |
}) | |
export class LazyReactComponentDirective<Comp extends ElementType> { | |
@Input() lazyReactComponent: () => Promise<Comp>; |