Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 为什么我不在模板中获取数组?_Angularjs - Fatal编程技术网

Angularjs 为什么我不在模板中获取数组?

Angularjs 为什么我不在模板中获取数组?,angularjs,Angularjs,我有一个调用AJAX的ng click方法showSchedules: $scope.showSchedules = function () { $scope.loadCalendar = true; appointmentService.getSchedule().then(function (response) { calendarService.set(response.data.cal

我有一个调用AJAX的ng click方法showSchedules:

$scope.showSchedules = function () {
                $scope.loadCalendar = true;
                appointmentService.getSchedule().then(function (response) {
                    calendarService.set(response.data.calendar, function () {


                        $timeout(function () {
                            $scope.refleshCalendars();
                            $scope.loadCalendar = false;
                            console.log($scope.events);

                        }, 100);

                    });
                });
            };
在这个方法中,您可以看到:console.log$scope.events; 它给我一个由对象填充的数组

当我在trmplatehtml中执行{{events}}时,我得到[]

为什么我得到空数组

HTML代码:

您需要{{vmx.events},因为您正在使用控制器作为注释

使用controller as可以清楚地知道您是哪个控制器 当多个控制器应用于一个控制器时,在模板中访问 元素


搜索controller as

您在哪里填写此事件?因此,如果您确定您的模板良好。看起来是对的。所以试着写$scope.events2=angular.copy$scope.events并检查模板中的events2。你真的把{{events}放在了与$scope.events具有相同作用域的模板中吗?我用{{events}{{vmx.events}演示了我的HTML代码!!!!!我在HTML模板中尝试了{{vmx.events}},是空的[]我也被删除了,因为在controllerI中,我会通过设置$scope.events='foo'来快速测试事件是否被正确绑定,当您执行该操作时,console.log如果该值在视图上没有更新,则会出现绑定问题,否则,在设置$scope.events时,您可能会遇到事件为空的问题
<div ng-controller="ScheduleController as vmx">
    {{events}}
    <mwl-calendar
        events="events"
        view="vmo.calendarView"
        view-title="vmo.calendarTitle"
        current-day="vmo.calendarDay"
        on-event-click="vmo.eventClicked(calendarEvent)"
        on-event-times-changed="vmo.eventTimesChanged(calendarEvent); 
            calendarEvent.startsAt = calendarNewEventStart; 
            calendarEvent.endsAt = calendarNewEventEnd"
        auto-open="true"
        day-view-start="06:00"
        day-view-end="23:00"
        day-view-split="30"
        cell-modifier="vmo.modifyCell(calendarCell)">
    </mwl-calendar>
</div>