내 나머지 통화에 내 변수 '되어 selectedDate'를 사용하기 위해 노력하고있어,하지만 항상 심지어 '() setSelectedDate'를 사용하여 새 값을 설정 한 후, 기존의 하나를 사용하는 기능ngResource의 기본 매개 변수
app.factory('MyService', function ($resource) {
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
var selectedDate = curr_month + "/" + curr_date + "/" + curr_year;
return {
getSelectedDate : function(){
return selectedDate;
},
setSelectedDate : function(newDate){
selectedDate = newDate;
console.log(selectedDate); // My setSelectedDate works well because I can see the new value in the console
},
// The selectedDate always return the first value (the new Date()), and not the updated date
Meal: $resource('/rest/food/meal', {date : selectedDate, mealId: '@mealId'}, {
query: {
method: 'GET',
isArray: true,
params : {date : selectedDate}
}
}),
}
});
내가 수동으로 내 컨트롤러에서 예를 들어, 다음과 같은 매개 변수를 설정하면 작동합니까 :
FoodService.setSelectedDate(newDate);
$scope.meals = FoodService.Meal.query(FoodService.getSelectedDate());
하지만 자동으로 '되어 selectedDate'변수를 사용하여 내 서비스를하고 싶은, 그냥 전화를해야 :
FoodService.setSelectedDate(newDate);
$scope.meals = FoodService.Meal.query();
하지만 항상 이전 날짜를 사용하고 업데이트 된 날짜는 사용하지 마십시오 ..
아이디어가 있으십니까?
편집 :
내가 PARAMS으로 시도하고, '/ 휴식/음식/식사'다음 후 $ 자원에 : - {날짜 : getSelectedDate} => ReferenceError가 : getSelectedDate이 을 정의되지 않은 - { 날짜 : getSelectedDate()} => 같은 - {날짜 : this.getSelectedDate()} => 형식 오류 : 개체 번호가있는 방법이 없습니다 'getSelectedDate'
마지막 .. 일을해야 하나 - {날짜 : selectedDate)} => 작동하지만 항상 처음에 selectedDate를 사용하지만 처음에 정의한 날짜는 사용하지 않습니다.
공장에 추가 된 새로운 getSelectedDate() 함수를 보았습니까? API 이름과 혼동을 일으키는 경우 이름을 바꿀 수 있습니다. – dmahapatro
도움을 주셔서 감사합니다. 기능 이름을 변경하려고했지만 여전히 동일한 문제가 있습니다. 내 매개 변수에서 정확히 무엇을 부를까요? getSelectedDate(), this.getSelectedDate(), selectedDate, others ..? – GSP59