0
angular.module('...', ['...'])
    .controller('main', main);

function main($scope, $firebaseArray) {
    $scope.assign = function() {
        $scope.assigned = $scope.deviceName;
    };
    $scope.today = function () {
        // must put to set hours before isostring
        $scope.dth = new Date();
        $scope.test = moment($scope.dth).format('YYYY-MM-DD');
        console.log($scope.test);
        // this console.log is to check if the date format is correct
    };
    $scope.today();

    $scope.inlineOptions = {
        customClass: getDayClass,
        minDate: new Date(),
        showWeeks: true
    };

    $scope.open1 = function () {
        $scope.popup1.opened = true;
    };

    $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
    $scope.format = $scope.formats[0];
    $scope.altInputFormats = ['M!/d!/yyyy'];

    $scope.popup1 = {
        opened: false
    };

    $scope.dateOptionsM = {
        formatYear: 'MM',
        startingDay: 1,
        minDate: new Date(2018, 0, 1, 0, 0, 0, 0),
        minMode: 'month'
    };

    $scope.dateOptionsY = {
        formatYear: 'yyyy',
        startingDay: 1,
        // minDate: start from which date
        minDate: new Date(2018, 0, 1, 0, 0, 0, 0),
        minMode: 'year'
    };

    function getDayClass(data) {
        var date = data.date,
            mode = data.mode;
        if (mode === 'day') {
            var dayToCheck = new Date(date).setHours(0, 0, 0, 0);

            for (var i = 0; i < $scope.events.length; i++) {
                var currentDay = new Date($scope.events[i].date).setHours(0, 0, 0, 0);

                if (dayToCheck === currentDay) {
                    return $scope.events[i].status;
                }
            }
        }

        return '';
    }


    $scope.$watch('[assigned, test]', function(values) {
        //UI for calendar function
        var newtest = values[1];
        var value = values[0];
        var newRef = firebase.database().ref('editedData').child(value);

        var hourRef = newRef.child('H');

        $scope.halfhourlyData = $firebaseArray(hourRef.orderByChild('timestamp').limitToLast(48).startAt(newtest));
        console.log(newtest);
        // this console log only displays once
        $scope.halfhourlyData.$loaded();

So what I want to do is to push the date that is set on the calendar into the startAt() function. However, upon testing, I realized that both logs only have been displayed once. Meaning that the value is not changing. However, on the HTML page the value does change and it uses $scope.dth. Is there a way for me to make the values change according to the calendar display? I'm using angular-bootstrap UI. Thanks!

Manish Balodia
  • 1,863
  • 2
  • 23
  • 37
  • It might help for an answer if you included the HTML associated with this controller code (e.g. how you've wired up `uib-datepicker`). However, from what you've provided, it appears you've bound `$scope.dth` to `uib-datepicker` then you're watching `test`, which obviously doesn't share the reference to `$scope.dth` (i.e. if the latter changes, the former won't). – miqh Jul 16 '18 at 04:26
  • ahh okok yes by binding it directly to $scope.dth it works! thank you! – Audrey Wong Jul 16 '18 at 05:03

0 Answers0