我为日期选择器创建了一个指令,我还有一个搜索指令,它是一个表单。所以搜索指令使用日期选择器指令。我有2个日期选择器,一个用于出发日期,另一个用于到达日期。我的问题是如何从日期选择器指令选择的值设置searchDateTime和arrivalDateTime。在执行搜索时,departureDateTime和arrivalDateTime都为空。如何让它向我显示正确的选定值?
app.directive('selectDate', [function(){
return {
restrict: 'E',
scope: {
dateObj: "&"
},
templateUrl: 'DateSelector.html',
controller: function($scope){
$scope.today = function(dateObj) {
$scope.dateObj = new Date();
};
$scope.today();
$scope.clear = function () {
$scope.dateObj = null;
};
// Disable weekend selection
$scope.disabled = function(date, mode) {
return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
};
$scope.toggleMin = function() {
$scope.minDate = $scope.minDate ? null : new Date();
};
$scope.toggleMin();
$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
`enter code here`$scope.format = 'dd-MMMM-yyyy';
},
controllerAs: 'dateCtrl'
};
}]);
app.directive('searchForm', ['sharedProperties',function(sharedProperties){
return {
restrict: 'E',
templateUrl: 'SearchForm.html',
link: function(scope, element){
var form = $("#search-form");
},
controller: function($scope){
$scope.departureDateTime= null;
$scope.arrivalDateTime = null;
$scope.search = function(){
console.log($scope.departureDateTime, $scope.arrivalDateTime);
}
},
controllerAs: 'form'
};
}]);
答案 0 :(得分:0)
使用"链接"功能可以解决这个问题 http://www.sitepoint.com/practical-guide-angularjs-directives/