TanStackT
TanStack6d ago
4 replies
ltd-scarlet

injectQuery result into signal

Hello, hello. I am just getting back into coding after a longer absence and not 100% familiar yet with all the new Angular concepts, so maybe I am overlooking something here. I am wondering how I can utilize the result of a injectQuery in my component directly? It is fine that I can access it in the template, that is why I want to have the query to show loading indicator and errors, but in my case I now want to combine the result with a form and load the values into the fields...

  catService = inject(CatService);

  query = injectQuery(() => ({
    queryKey: ['cat', '123'],
    queryFn: (): Promise<ICat> => this.catService.getCat('123'),
  }));

  readonly data = signal<ICat | undefined>(this.query.data()); // <-- How would I make this work? 

  form = injectForm({
    defaultValues: this.data() || defaultCat,
    onSubmit({ value }) {
      // Do something with form data
      console.log(value);
    },
  });
Was this page helpful?