Having trouble retrieving data from a web api and passing it back to a JavaScript file. I've tried using http://localhost:8584/api/Testing/5 to see if there are any results, but no luck so far.
//This is the JavaScript controller that calls the service.js
app.controller('mainController', function ($scope, service) {
returnData();
function returnData() {
var getData = service.get(5);
//The data returned from the web api will be displayed with $scope.newmessage
getData.then(function (pl) { $scope.newmessage = pl.data },
function (errorPl) {
$log.error('failure loading Employee', errorPl);
});
}
}
//this is service.js
app.service('service', function ($http) {
var baseUrl = 'http://localhost:8584/';
this.get = function (Id) {
return $http.get(baseUrl + 'api/Testing/' + Id);
}
});
//This is my web API controller
namespace angulartestOne.Controllers
{
public class TestingController : ApiController
{
// GET api/<controller>
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/<controller>/5
public string Get(int id)
{
return "value";
}
// POST api/<controller>
public void Post([FromBody]string value)
{
}
// PUT api/<controller>/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/<controller>/5
public void Delete(int id)
{
}
}
}