C # Web API I want to build a JSON and receive it with AngularJS 5/6

0

I want to build a JSON from the backend where the texts will come according to the language configured by the user.

In the backend I am using a Web API from .net and I want to take that JSON in the frontend AngularJS 5/6 and somehow I can use it if it is not possible to store it in a file or if it can be used as an object.

I have little experience in AngularJS, currently the frontend handles some JSON that is physically in the files of the frontend project.

Thank you in advance.

    
asked by Jesús Rojas 13.09.2018 в 22:18
source

1 answer

0

First of all "AngularJS" is different from Angular. for the versions of Angular2 and above it is only "Angular".

in the controller of your api you can send the data in this way

[HttpGet]
public async Task<IActionResult> GetCategory(int id)
    {
        var categoryModel = await _categoryService.FindCategoryModelById(id);
        if(categoryModel == null)
        {
            return new OkObjectResult(new
            {
                Message = "Categoria con id = " + id + " no existe",
                categoryModel
            });
        }
        return new OkObjectResult(new
        {
            categoryModel
        });
    }

public class CategoryModel
{
    public int Id { get; set; }
    public string Description { get; set; }
    public Boolean State { get; set; } = true;
}

assumes that _categoryService is a service that brings you a defined category

with angular with Get requests you can receive this information as a json

    
answered by 14.09.2018 в 00:06