I am trying to develop a simple web application using angularjs
i have a table city
that is created using entityframework database first
.
I added angularjs nuget to my project.and create 2 files in my project named service
and controller
as you can see here :
controller
MyApp.controller('UpdateController', function ($scope, CityService) {
getCities();
function getCities() {
CityService.getCities()
.success(function (cities) {
$scope.cities = cities;
})
.error(function (error) {
$scope.status = 'Unable to load customer data: ' + error.message;
});
}
});
Service :
MyApp.factory('CityService', ['$http', function ($http)
{
var urlBase = 'http://localhost:37404/api';
var CityService = {};
CityService.getCities = function () {
return $http.get(urlBase + '/default1');
};
return CityService;
}]);
I pass the data using webapi as you can see :
namespace MvcApplication8.Controllers
{
public class Default1Controller : ApiController
{
private testDBEntities db = new testDBEntities();
// GET: api/ManageStudentsInfoAPI
public IQueryable<City> GetStudent()
{
return db.Cities;
}
}
}
Here is my view :
<header>
<div class="content-wrapper">
<div class="float-left">
<p class="site-title">
<a href="~/">ASP.NET Web API</a></p>
</div>
</div>
<script src="~/Scripts/jquery-1.7.1.js"></script>
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/MyAngularFile/Service.js"></script>
<script src="~/MyAngularFile/Controller.js"></script>
</header>
<div id="body">
<div ng-controller="UpdateController">
<table class="table">
<tr>
<th>Id</th>
<th>Name</th>
<th>Country</th>
</tr>
<tr ng-repeat="a in cities">
<td>{{a.Id}}</td>
<td>{{a.Name}}</td>
<td>{{a.Country}}</td>
</tr>
</table>
</div>
</div>
But the result is like this :
My browser errors:
ng-app
specified in the html code? Are there any errors in the browser console (Ctrl+shift+i to bring it up)?ng-app="MyApp"
attribute, for example in the body tag. Also, the browser console complains that MyApp hasn't been defined. You probably need to addvar MyApp = angular.module('MyApp', []);
in the Service.js file.