私はAngularJSが初めてで、サンプルに取り組んでいます。私のサンプルアプリには、MVC Web API (db からデータを返す) があり、Angular Services から呼び出され、データが Controller に返されます。問題は、サービスの成功メソッドでデータを適切に取得していることですが、コントローラーでは常に未定義と表示され、ビューには何も表示されません。以下のコードを参照してください。
私のコントローラーコード:
app.controller('CustomerController', function ($scope, customerService) {
//Perform the initialization
init();
function init() {
$scope.customers= customerService.getCustomers();
}
});
マイ サービス コード:
app.service('customerService', function ($http){
this.getCustomers = function () {
$http({
method: 'GET',
url: 'api/customer'
}).
success(function (data, status, headers, config) {
return data;
}).
error(function (data, status) {
console.log("Request Failed");
});
}
});
この問題を解決するのを手伝ってください。