나는 editingTimesheet와 allowed_times (이 것은 editingTimesheet의 날짜를 기준으로 계산 됨) 목록이 필요한 템플릿을 가지고 있습니다.
나는 컨트롤러의 코드 만에 사용되는 I는 $의 state.go을 수행 할 때 (
가) 나는 상태에서 그 결의를 (본 비디오 년대 지식인을보고 한 번이 아니라 실행하는 것 같다 발견 폼을 열기 전에로드 할 데이터를 강제로로드하십시오. 내가 지금 가지고있는 코드를 사용하면 editingTimesheet가로드되기 전에 $ scope.timesheet가 설정됩니다 (allowed_times와 동일합니다.)
내 서비스에서 이 코드를 가지고 :
.factory('Timesheets', function($resource, $rootScope, LinkData, Company) {
var Timesheet = $resource('http://127.0.0.1:3000/api/v1/timesheets/:id',{id:'@id'}, {update:{method:'PUT'}});
var _allowed_times;
return {
timesheet: function() {
return Timesheet;
},
allowed_times: function() {
return this._allowed_times
},
get: function(id){
return Timesheet.query({q: {id_eq: id}}).$promise.then(function (data, status) {
this.editingTimesheet = data;
Company.allowed_times(data.currentDate).then(function(data2) { //fill allowed times
this._allowed_times = data2;
});
});
}
}
})
컨트롤러 나는이 있습니다
var TimesheetDetailCtrl = app.controller('TimesheetDetailCtrl', function($scope, Timesheets) {
$scope.allowed_times = Timesheets.allowed_times();
$scope.timesheet = Timesheets.editingTimesheet;
}
나는 또한 내가 .STATE에 해결하기 위해 매핑이 기능을 가지고있다 :
TimesheetDetailCtrl.beforeShow = function($q, $stateParams, Timesheets) {
Timesheets.get($stateParams.timesheetId);
};
을 마지막으로 나는이 상태가 :
.state('timesheet-detail', {
url: '/timesheet/:timesheetId',
templateUrl: 'templates/timesheet-detail.html',
controller: 'TimesheetDetailCtrl',
resolve: {
reset: TimesheetDetailCtrl.beforeShow
}
})
을 추가 질문 : beforeShow 함수는 템플릿이로드 될 때마다 실행됩니다. 컨트롤러의 코드하지 :
$scope.timesheet = Timesheets.editingTimesheet;
오전 나는 가정 올바른 그 Timesheets.editingTimesheet 변경, 자동 또한 $의 scope.timesheet을 변경하고 컨트롤러의 코드를 실행할 필요가 없습니다 이유입니다 때 매번?