Ich habe etwas Wissen über Angularjs, aber ich bin neu in ASP.NET MVC. Also folgte ich diesem Tutorial https://docs.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api. Aber ich habe ein Problem, da es Jquery verwendet. Ich möchte auf die hartcodierten Daten im unteren Controller mit Angular zugreifen.Zugriff auf fest codierte Daten in MVC-Controller mit Angularjs
using ProductsApp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web.Http;
namespace ProductsApp.Controllers
{
public class ProductsController : ApiController
{
Product[] products = new Product[]
{
new Product { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 },
new Product { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M },
new Product { Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M }
};
public IEnumerable<Product> GetAllProducts()
{
return products;
}
public IHttpActionResult GetProduct(int id)
{
var product = products.FirstOrDefault((p) => p.Id == id);
if (product == null)
{
return NotFound();
}
return Ok(product);
}
}
}
Ich möchte nur die Methode auf die Daten zugreifen.
Kann mir jemand dabei helfen. Danke
ist verwenden, um zu nennen es ähnlich sein wird, - Siehe ['$ http'] (https://docs.angularjs.org/api/ng/service/$http). – EdSF