私はモジュールコントローラから都市を表示する簡単なAngularJSを開発しています。私の単純なAngularjsコードは結果を表示しません
これは私のコードです:
// module:
var myApp = angular.module('myApp', []);
//Service:
myApp.service('myService', function ($http) {
this.getCities = function() {
return $http.get('/City/GetCities');
}
});
//Controller:
myApp.controller('myController', function ($scope, myService) {
getCitiesList();
function getCitiesList() {
var getCitiesList = myService.getCities();
getCitiesList.then(function (emp) {
$scope.cities = emp.data;
}, function() { alert('Not Found'); });
}
});
CSHTMLファイル:
@{
ViewBag.Title = "View1";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>View1</h2>
@section scripts{
<script src="~/Scripts/angular.min.js"></script>
<script src="~/js/angulartest.js"></script>
}
<div ng-app="myApp">
<div ng-controller="myController">
<table>
<tr>
<td>
ID
</td>
<td>
Name
</td>
</tr>
<tr ng-repeat="x in citiesList">
<td>
{{x.ID_City}}
</td>
<td>
{{x.CityName}}
</td>
</tr>
</table>
</div>
</div>
私はMVCコントローラコードをトレースします。 City/GetCities JsonResultを起動して返しますが、angularjsコントローラには結果が表示されません。あなたのHTML内
コンソール都市内約束成功方法...データを正しく取得しているかどうかを確認してください...テンプレートコードの中でcitiesListの代わりに$ ctrl.citiesを使用してください。 – Ajay