Hi srivatchu,
Your Web API method returning string value and you are trying to loop through the data using ng-repeat directive which is not possible.
If you want loop and write data then you need to return List or Array from Web API method and display using ng-repeat directive.
If you are returning string message then display the string message without using ng-repeat directive.
Check the below example.
Namespaces
using System.Web.Http;
API Controller
public class EmployeeInformationController : ApiController
{
[Route("api/EmployeeInformation/Get")]
[HttpGet]
public string Get()
{
string content = "Hello World";
return content;
}
[Route("api/EmployeeInformation/GetArray")]
[HttpGet]
public string[] GetArray()
{
string content = "Hello World,Welcome";
return content.Split(',');
}
}
HTML
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', [])
app.controller('MyController', function ($scope, $http) {
$http.get('https://localhost:44323/api/EmployeeInformation/Get')
.then(function (response) {
$scope.greeting = response.data;
});
$http.get('https://localhost:44323/api/EmployeeInformation/GetArray')
.then(function (response) {
$scope.greetingArray = response.data;
});
});
</script>
</head>
<body>
<div ng-controller="MyController">
<p>The content is {{greeting}}</p><hr />
<p ng-repeat="m in greetingArray">The content is {{m}}</p>
</div>
</body>
</html>
Screenshot