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();

所以我想要做的是将日历上设置的日期推送到startAt()函数中。但是,经过测试,我意识到这两个日志都只显示了一次。意思是价值没有改变。但是,在 HTML 页面上,值确实发生了变化,它使用$scope.dth. 有没有办法让我根据日历显示改变值?我正在使用角度引导 UI。谢谢!

4

0 回答 0