最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How does new resource work in new angular version? - Stack Overflow

programmeradmin3浏览0评论

So in my service I am setting the signal symbolChangeSignal = signal<number>(0);

now in component ABC i am creating resource

    request: () => {
      let script = this.stateService.symbolChangeSignal()
    },
    loader: ({ request }) => {
      return apicallhere
    }
  });

ponent.ts

take a look at this example In above you will find a service which on app load intitialized id signal with init value 0.

In app child there is rxResource using this signal. But app child comes in play after 1 second. Only after that child component rxResource is intitialized. How come resource is making an API call and loading data here using id value 1. Even though signal value is not changed after resource declare/init.

The document states that the resource produces a new request value on signal change. However, it is not mentioned anywhere in the document that upon resource initialization, the loader will be called once using the previous value or initialised value of the signal.

So in my service I am setting the signal symbolChangeSignal = signal<number>(0);

now in component ABC i am creating resource

    request: () => {
      let script = this.stateService.symbolChangeSignal()
    },
    loader: ({ request }) => {
      return apicallhere
    }
  });

https://stackblitz.com/edit/stackblitz-starters-mjzjkrpq?file=src%2Fapp%2Fchild.component.ts

take a look at this example In above you will find a service which on app load intitialized id signal with init value 0.

In app child there is rxResource using this signal. But app child comes in play after 1 second. Only after that child component rxResource is intitialized. How come resource is making an API call and loading data here using id value 1. Even though signal value is not changed after resource declare/init.

The document states that the resource produces a new request value on signal change. However, it is not mentioned anywhere in the document that upon resource initialization, the loader will be called once using the previous value or initialised value of the signal.

Share Improve this question asked Feb 7 at 8:30 Nikunj GunaNikunj Guna 212 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I'll give you the same answer here,

Resources are eager, they evaluate the request and pass that value down to the loader which will eventually return the value of the resource.

And on subsequents changes of the request signals, the request will be recomputed and re-trigger the loader.

This is the same way an effect or a computed would work.

发布评论

评论列表(0)

  1. 暂无评论