私はかなりシンプルなアプリケーションを書いていますが、私は編集(編集コントローラ)部分のコードに固執しているようです。私は学生のリストを持っています、私は更新のために1つを選択します。しかし、私は "オブジェクトを含むが、配列を持っている期待された応答"というエラーを取得します。単一オブジェクトの代わりに複製オブジェクトの配列を取得する
を取得するが、私は要素を検査し、ネットワーク]タブに移動したときに、私はこの
を参照してくださいここに私のコードです。
var StudentManagement = angular.module('StudentManagement', ['ngRoute','ngResource','ui.bootstrap']);
StudentManagement.config(function ($routeProvider) {
$routeProvider
.when("/", {
templateUrl: "list.html",
controller: "HomeController"
})
.when("/add", {
templateUrl: "add.html",
controller: "AddController"
})
.when("/edit/:editId", {
templateUrl: "edit.html",
controller: "EditController"
})
.otherwise({
redirectTo: "/"
});
});
StudentManagement.factory('Student', function ($resource) {
return $resource('/api/Student/:id', { id: '@id' }, { update: { method: 'PUT' } });
});
StudentManagement.controller("HomeController",
function ($scope, $location, Student) {
$scope.search = function() {
$scope.students = Student.query();
};// end search
$scope.reset = function()
{
$scope.search();
}// end reset function
$scope.search();
});
StudentManagement.controller("EditController",
function ($scope, $location, $routeParams, Student) {
// get the student given the specific id
var id = $routeParams.editId;
$scope.student=Student.get({id: id});
$scope.updateForm = function() {
Student.update({id:id}, $scope.student, function() {
$location.path('/');
});
}// end edit function
$scope.cancelForm = function() {
$location.path('/');
}// end cancel function
});
現在のコードが実行可能なようにしたい場合は、あなたがあなたのAPIのArrayを返却する場合、あなたがでIsArray使用する必要があるサーバー
からオブジェクトのオブジェクトを返すことができます。サービスメソッドでtrueです。 – nikhil
それは配列を返すべきではないので、私はブラウザから直接Apiを呼び出すとき、[{"id":5、 "firstname": "somaya"、 "lastname": "bliss"、 "age ":20、" studentId ":" 1A40000000 "}]。アレイがフロントエンドで作成されている理由は何ですか? – nahaelem
その配列...角括弧は配列を表しています。あなたは明らかにサーバーから配列を返しています。 – nikhil