サーバーからデータを取得しているファイルはservices.js
です。私はメインのスクリプトメソッドのフォームのサービス層にデータを取得していないが、メインのスクリプトファイルがあります。別途サービスでWeb APIを使用して作業中にデータを取得していません
BLOCKQUOTE
コードを確認してください、と私は間違いを持っているなら、私に知らせてください。
app.factory("studentServices", function ($http)##
----------
##
return {
postData: function (student) {
$http.post("/api/Student/Register", student)
.then(function (response) {
console.info(response.data);
debugger;
return response.data;
}, function (error) {
console.info("error in reruest");
});
},
getData: function() {
debugger;
var rt;
$http.get("/api/Student/getStudent").then(function (response) {
console.info(response.data);
debugger;
rt=response.data;
}, function (error) { console.info("error in geting"); })
debugger;
return rt;
}
}
})
/// <reference path="../Scripts/angular.js" />
/// <reference path="script.js" />
var app = angular.module("myModule", []).controller("myController", function ($scope, $http, studentServices) {
debugger;
console.info("init");
$scope.addStudent = function() {
console.info("just");
console.info($scope.id);
$scope.result="";
var student = {id:$scope.id,name:$scope.name,email:$scope.email,college:$scope.college,mobile:$scope.mobile}
console.info(student);
// $http.post("/api/Student/Register", student).then(function (response) {
// console.info(response.data);
$scope.result = studentServices.postData(student);
console.info("result " + $scope.result);
get();
// }, function (error) { console.info("error in reruest") })
//$scope.getStudents();
}
$scope.getStudents = function get() {
debugger;
console.info("gettinf studetn list");
// $http.get("/api/Student/getStudent").then(function (response) {
// console.info(response.data);
var local = studentServices.getData();
debugger;
$scope.students = local; //response.data;
debugger;
console.info("getdata list ");
// }, function (error) { console.info("error in geting") })
}
console.info("last");
})
ファクトリメソッドを呼び出す場所? – anoop