SHARE
TWEET
shortver
a guest
Dec 23rd, 2014
178
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- CONTROLLER:
- ===========
- I had this object literal:
- =======================================
- // $scope.rangeSelected = {
- // from: new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * 14),
- // to: new Date()
- //};
- I had to changed it to this in order to make it work:
- ======================================================
- $scope.from = new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * 14);
- $scope.to = new Date();
- VIEW:
- =====
- before (not working):
- ======================
- <cd-top range='rangeSelected'></cd-top>
- after (working):
- ==================
- <cd-top from='from' to='to'></cd-top>
- DIRECTIVE:
- =========
- directives.directive('cdTop', [function(){
- return {
- restrict: 'E',
- scope: { from: '=', to: '=' },
- templateUrl: 'partials/cdTop.html?d=' + new Date().getTime(),
- controller: function($scope, $element, $attrs, $transclude) {
- //not relevant
- },
- link: function($scope, iElm, iAttrs, controller) {
- var to = new Date($scope.to.getTime());//new Date($scope.range.to.getTime())
- var from = new Date($scope.from.getTime());//new Date($scope.range.from.getTime())
- var jqCalendar = iElm.find('#datepicker-calendar');
- var jqSelector = iElm.find('#date-range-field');
- jqCalendar.DatePicker({
- inline: true,
- date: [from, to],
- calendars: 2,
- mode: 'range',
- //current: new Date(to.getFullYear(), to.getMonth() - 1, 1),
- onChange: function(dates,el) {
- //$scope.range.from = new Date(dates[0].getTime()); //only worked once
- //$scope.range.to = new Date(dates[1].getTime());//only worked once
- $scope.from = new Date(dates[0].getTime()); //ok
- $scope.to = new Date(dates[1].getTime()); //ok
- $scope.$apply();
- }
- });
- jqSelector.on('click', function() {
- jqCalendar.toggle();
- });
- // $scope.$watch('from', function(obj1){
- // console.warn(obj1);
- // }, true);
- // $scope.$watch('to', function(obj1){
- // console.warn(obj1);
- // }, true);
- }
- };
- }]);
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.

