SHARE
TWEET

shortver

a guest Dec 23rd, 2014 178 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CONTROLLER:
  2. ===========
  3. I had this object literal:
  4. =======================================
  5. // $scope.rangeSelected = {
  6. //     from: new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * 14),
  7. //     to: new Date()
  8. //};
  9.  
  10. I had to changed it to this in order to make it work:
  11. ======================================================
  12. $scope.from = new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * 14);
  13. $scope.to = new Date();
  14.  
  15.  
  16. VIEW:
  17. =====
  18. before (not working):
  19. ======================
  20. <cd-top range='rangeSelected'></cd-top>
  21.  
  22. after (working):
  23. ==================
  24. <cd-top from='from' to='to'></cd-top>
  25.  
  26. DIRECTIVE:
  27. =========
  28. directives.directive('cdTop', [function(){
  29.     return {
  30.         restrict: 'E',
  31.         scope: { from: '=', to: '=' },
  32.         templateUrl: 'partials/cdTop.html?d=' + new Date().getTime(),
  33.         controller: function($scope, $element, $attrs, $transclude) {
  34.                 //not relevant
  35.         },
  36.         link: function($scope, iElm, iAttrs, controller) {
  37.  
  38.                     var to = new Date($scope.to.getTime());//new Date($scope.range.to.getTime())
  39.                     var from = new Date($scope.from.getTime());//new Date($scope.range.from.getTime())
  40.                     var jqCalendar = iElm.find('#datepicker-calendar');
  41.                     var jqSelector = iElm.find('#date-range-field');
  42.  
  43.                     jqCalendar.DatePicker({
  44.                         inline: true,
  45.                         date: [from, to],
  46.                         calendars: 2,
  47.                         mode: 'range',
  48.                         //current: new Date(to.getFullYear(), to.getMonth() - 1, 1),
  49.                         onChange: function(dates,el) {
  50.                             //$scope.range.from = new Date(dates[0].getTime()); //only worked once
  51.                             //$scope.range.to = new Date(dates[1].getTime());//only worked once
  52.                             $scope.from = new Date(dates[0].getTime()); //ok
  53.                             $scope.to = new Date(dates[1].getTime()); //ok
  54.                             $scope.$apply();
  55.                         }
  56.                     });
  57.  
  58.                     jqSelector.on('click', function() {
  59.                         jqCalendar.toggle();
  60.                     });
  61.  
  62.                 // $scope.$watch('from', function(obj1){
  63.                 //     console.warn(obj1);
  64.                 // }, true);
  65.                 // $scope.$watch('to', function(obj1){
  66.                 //     console.warn(obj1);
  67.                 // }, true);
  68.  
  69.         }        
  70.     };
  71. }]);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top