フロントエンドにはAngularJSを使用し、バックエンドにはJava(Spring)を使用するアプリケーションに取り組んでいます。アプリケーションはhttp://localhost:8080/Sprint002/restpatent/
をリクエストして、ApacheとTomcatの両方を実行しています(ポート80のApache)。未定義のプロパティを読み取ることができません - コードまたはサーバーで問題がありますか?
エラーTypeError: Cannot read property 'fetchAllUsers' of undefined
が返されます。だから私が見ることができるのは、オブジェクトが見つからないということです。 ApacheとTomcatを同時に実行することに問題はありますか?そうでない場合は、理由は何ですか?
app.controller('UserController', ['UserService', function($scope, UserService) {
var self = this;
self.user={id:null,username:'',address:'',email:''};
self.users=[];
self.submit = submit;
self.edit = edit;
self.remove = remove;
self.reset = reset;
console.log('hello')
fetchAllUsers();
function fetchAllUsers(){
console.log('hello2');
UserService.fetchAllUsers()
.then(
function(d) {
self.users = d;
},
function(errResponse){
console.error('Error while fetching Users');
}
);
}
app.factory('UserService', ['$http', '$q', function($http, $q){
console.log('hello3')
var REST_SERVICE_URI = 'http://localhost:8080/Sprint002/restpatent/';
var factory = {
fetchAllUsers: fetchAllUsers,
createUser: createUser,
updateUser:updateUser,
deleteUser:deleteUser
};
return factory;
function fetchAllUsers() {
var deferred = $q.defer();
console.log('hello4')
$http.get(REST_SERVICE_URI)
.then(
function (response) { //success
deferred.resolve(response.data); //processes the data
},
function(errResponse){ //error
console.error('Error while fetching Users');
deferred.reject(errResponse); //rejects the data
}
);
return deferred.promise;
}
[{"id":1,"applicationNumber":"N8167625","clientRef":"TER-34421","costToRenew":"534","renewalDueDate":"30/09/2017","basketStatus":"Cannot add to Basket"},{"id":2,"applicationNumber":"W71679234","clientRef":"Breitling","costToRenew":"5367","renewalDueDate":"30/11/2017","basketStatus":"Add to Basket"},{"id":3,"applicationNumber":"T7167921","clientRef":"Rolex","costToRenew":"8341","renewalDueDate":"30/05/2017","basketStatus":"In Basket"},{"id":4,"applicationNumber":"uk167444","clientRef":"Timex","costToRenew":"8341","renewalDueDate":"30/02/2017","basketStatus":"Add to Basket"}]
あなたはこの工場をどこに注入するのですか? – quirimmo
今更新されました –
あなたは注入中にエラーが発生しました。答え、それを試してみましょう – quirimmo