【问题标题】:How To Send String Value To Back end in an Angular get request如何在 Angular 获取请求中将字符串值发送到后端
【发布时间】:2019-05-11 03:59:31
【问题描述】:

我期待在网址中附加股票名称的网络核心。代码如下:

[Route("api/[controller]")]
[ApiController]
public class StockController : ControllerBase
{
    private static readonly Random generator = new Random();

    // GET api/stock/aapl
    [HttpGet("{r}")]
    public ActionResult<float[]> Get(
        string r,

我不确定 Angular get 中的格式。这就是我所拥有的:

  getStock(name: string) {
// url should be api/stock/aapl
console.log("this.http.get<Cagr[]>(this.apiURL + '/api/stock' + {name});", this.http.get<Cagr[]>(this.apiURL + '/api/stock' + {name}))

return this.http.get<Cagr[]>(this.apiURL + '/api/stock' + {name});
}

后端和前端都编译。 console.log 语句将此发送到控制台,格式不准确:

console.log("this.http.get<Cagr[]>(this.apiURL + '/api/stock' + {name});", this.http.get<Cagr[]>(this.apiURL + '/api/stock' + {name}))

我应该使用什么格式?

【问题讨论】:

    标签: angular asp.net-core


    【解决方案1】:

    您似乎缺少一个斜线。如果您使用占位符而不是内联连接,您的代码将更具可读性

    const url = `${this.apiURL}/api/stock/${name}`;
    return this.http.get<Cagr[]>(url);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-02
      • 2020-02-04
      • 1970-01-01
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 2013-09-29
      • 2022-07-14
      相关资源
      最近更新 更多