从jquery调用Angularjs函数不允许更改变量

时间:2015-10-28 16:37:20

标签: javascript jquery arrays angularjs html5

我的范围内有一个变量,当我尝试在函数中重置它时,它会抛出异常。 如果有人对此有所了解,请分享解决方案。

You can find the full code in this jsFiddle. 如果删除第173行,代码将起作用。

控制器变量声明:

angular.module('timeSheetApp', []).controller('TimeSheetController', function ($scope, $http) {
$scope.TimeSheet = {
        Tables: [{
            Projects:{
                Project: ":)",
                Activities: [{
                    Activity:"",
                    Sun: 0.00,
                    Mon: 0.00,
                    Tue: 0.00,
                    Wen: 0.00,
                    Thu: 0.00,
                    Fri: 0.00,
                    Sat: 0.00,
                    Total: 0.00
                }],
                DefaultProjectText: "Select a Project",
                IsDisabled: true,
                ProjectNumber: 0,
                Day: {}
            }
        }],
};
});

`

当我在控制器中调用此函数时发送异常:

 $scope.SetDays = function () {

    $scope.TimeSheet.Tables = [{
            Projects: {
                Project: ":)",
                Activities: [{
                    Activity: "",
                    Sun: 0.00,
                    Mon: 0.00,
                    Tue: 0.00,
                    Wen: 0.00,
                    Thu: 0.00,
                    Fri: 0.00,
                    Sat: 0.00,
                    Total: 0.00
                }],
                DefaultProjectText: "Select a Project",
                IsDisabled: true,
                ProjectNumber: 0,
                Day: {}
            }
        }]

}

这是jquery Call:

   <script type="text/javascript">
            $(function () {
                var startDate;
                var endDate;

                localStorage.clear();
                //localStorage.removeItem('endDate');

                $('#containerId').css('margin-left', '5%');
                $('#containerId').css('margin-right', '5%');
                $('#containerId').css('width', '100%');

                var selectCurrentWeek = function () {
                    window.setTimeout(function () {
                        $('.week-picker').find('.ui-datepicker-current-day a').addClass('ui-state-active')
                    }, 1);
                }


                $('.week-picker').datepicker({
                    showOtherMonths: true,
                    selectOtherMonths: true,
                    onSelect: function (dateText, inst) {
                        var date = $(this).datepicker('getDate');
                        startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay());
                        endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 6);
                        var dateFormat = inst.settings.dateFormat || $.datepicker._defaults.dateFormat;
                        $('#startDate').text($.datepicker.formatDate(dateFormat, startDate, inst.settings));
                        $('#endDate').text($.datepicker.formatDate(dateFormat, endDate, inst.settings));

                        var daysInMonth = new Date(date.getFullYear(), date.getMonth(), 0).getDate();
                        localStorage.setItem('daysInMonth', daysInMonth);
                        localStorage.setItem('endDate', date.getDate() - date.getDay() + 6);
                        selectCurrentWeek();
                        angular.element('#TimeSheetController').scope().SetDays();
                        angular.element('#TimeSheetController').scope().$apply();
                    },
                    beforeShowDay: function (date) {
                        var cssClass = '';
                        if (date >= startDate && date <= endDate)
                            cssClass = 'ui-datepicker-current-day';
                        return [true, cssClass];
                    },
                    onChangeMonthYear: function (year, month, inst) {
                        selectCurrentWeek();
                    }
                });
                $('.week-picker .ui-datepicker-calendar tr').find('.ui-datepicker-current-day').click();

                $('.week-picker .ui-datepicker-calendar tr').live('mousemove', function () { $(this).find('td a').addClass('ui-state-hover'); });
                $('.week-picker .ui-datepicker-calendar tr').live('mouseleave', function () { $(this).find('td a').removeClass('ui-state-hover'); });
            });
            </script>

0 个答案:

没有答案