0
對於AddVisitController,我創建了一個訪問模型,它接受諸如標題,開始日期,結束日期和說明等屬性。它會將我重定向到一個頁面,在那裏我可以點擊一個按鈕來添加旅行。所有的屬性都存儲在一個模型中。爲了增加訪問模式,我希望在訪問之前獲取訪問的ID,然後才能插入訪問值。我如何獲得訪問ID?獲取id,然後放入值
.controller('AddVisitController', ['$scope', '$state', 'Visit', function ($scope, $state, Visit) {
$scope.visits = [];
$scope.submitForm = function() {
Visit
.upsert({
vTitle: $scope.visit.vTitle,
startDate: $scope.visit.startDate,
endDate: $scope.visit.endDate,
dDescription: $scope.visit.vDescription
})
.$promise
.then(function() {
$state.go('create-trip');
});
};
}])
添加行程控制器
.controller('AddTripController', ['$scope', '$q', 'Visit', '$stateParams', '$state', function ($scope, $q, Visit, $stateParams, $state) {
$scope.visits = [];
$q
.all([
Visit.find().$promise,
Visit.findById({ id: $stateParams.id }).$promise
])
$scope.submitForm = function() {
Visit
.upsert({
day: $scope.visit.day,
date: $scope.visit.date,
tTitle: $scope.visit.tTitle,
startTime: $scope.visit.startTime,
endTime: $scope.visit.endTime,
tDescription: $scope.visit.tDescription
})
.$save()
.then(function (visit) {
$state.go('main-feed');
});
};
}])