0
我试图从指令中的链接函数设置范围值,但似乎没有工作。在指令链接功能中更改范围
我基本上是试图在用户如下改变日期选取器字段设置一个范围值...
app.directive('searchForm', function() {
return{
replace: true,
restrict: 'E',
templateUrl: "/app/views/sales/search/search-form.html",
link: function(element,attrs,scope){
$('.checkIn').datepicker({
minDate: new Date(),
onSelect: function(date){
var selectedDate = new Date(date);
var msecsInADay = 86400000;
var endDate = new Date(selectedDate.getTime() + msecsInADay);
$(".checkOut").datepicker("option", "minDate", endDate);
$(".checkOut").datepicker("option", "maxDate", '+2y');
$('.checkOut').attr('disabled', false);
if($('.checkOut').val()){
$('.numNights').val(($('.checkOut').datepicker('getDate') - $(this).datepicker('getDate'))/1000/60/60/24);
}
}
});
$('.checkOut').datepicker({
onSelect :function(){
scope.$apply(function(){
scope.search.nights = "Test";
});
}
});
}
};
});
我也试过scope.$apply()
但这也不起作用。
任何帮助非常感谢。
谢谢!这工作! –