如何使 DTO(数据传输对象)适应我的 Angular 项目?

问题描述 投票:0回答:1

我需要知道如何使 C# DTO 适应我的 Angular 6 项目。

例如我有这个DTO:

using System;
using System.Collections.Generic;
using System.Text;

namespace TriageMedico.DTOs
{
    public class BaseDto
    {
        public int Id { get; set; }
    }
}

我需要知道如何使用它,以便生成/创建模型,然后使用它发送 HTTP 请求。

c# angular dto
1个回答
0
投票

只需在打字稿上制作一个界面

export interface BaseDTO {
   id: number;
}

当您向后端执行 httpRequest 时,您将响应键入为 BaseDTO

myService.subscribe( (response: BaseDTO) => { ... some code here...  } );

我不知道是哪个(HttpClient 还是 Angular 本身),但它足够智能,可以将 C# 接口的属性映射到打字稿。但你需要匹配名字。

© www.soinside.com 2019 - 2024. All rights reserved.