2016-01-20 56 views
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()但這也不起作用。

任何幫助非常感謝。

回答

1

您「鏈接」功能有錯誤的簽名。它應該是:

function link (scope, element, attrs, controller, transcludeFn) { ... } 

創建操縱在documentation的DOM部分中的指令。或者更好的是這個document

+0

謝謝!這工作! –