首页 > 解决方案 > 另一个不是订阅的语法

问题描述

目标:
检索数据。

问题:
是否有另一种方法来检索数据而不是使用语法代码“订阅”?

信息:
我是 Angular 的新手

Component.ts

this._testService.SentApplicationByIdPersonprofileid(personprofilid).subscribe(data => {
      this._sentApplicationByIdPersonprofileid = data as SentApplicationByIdPersonprofileid[];
    });    



service.ts

SentApplicationByIdPersonprofileid(id: number)
{
    return this._http.get(url + 'api/SentApplicationByIdPersonprofileid/' + id);
}



asp.net core API

public ActionResult<IEnumerable<SentApplicationByIdPersonprofileid>> SentApplicationByIdPersonprofileid(int id)
{
....
....
....
}

标签: angular

解决方案


这是获取数据的最简单方法。每个观察者模式在幕前或幕后都遵循 pub/sub 设计模式。就像在 redux 中一样,您不需要显式地键入 subscribe 来获取数据,但是 redux 会在幕后为您编写订阅。对于大型应用程序,更好的方法是使用 ngrx/store。您通常不使用 subscribe 方法,而是调度操作和 ngrx 为您调用 subscribe 。

这是ngrx/store的链接: https ://ngrx.io/guide/store


推荐阅读