Angular:$ scope变量更改后的空白页面

时间:2016-05-05 12:42:13

标签: javascript angularjs ajax

我有一个角度应用程序,在点击链接后会路由到名为viewAll.html的模板。

此页面包含一些通过范围变量通过AJAX填充的数据。

问题是每当我通过AJAX更新这些范围变量并尝试渲染它时,页面就会变成空白。模板无法加载。

以下是代码:

$http({
    method: 'post',
    url: appContext('MarkMessageAsReadV2.json'),
    data: {
        "customerNotificationId":"", 
        "isRead":"Y", 
        "channelTypeCode":"101", 
        "readAll":"Y", 
        "customerType": "A"
    }
}).success(function (data) {
    $http.post(appContext('ViewAllNotificationsV2.json'), {
            "categoryGroupType":"ROLB",
            "isArchived":"N",
            "channelTypeCode":"101",
            "limit":"20",
            "page":"0",
            "customerType": "A"
        }).success(function(content, status, headers, config) {
            $scope.notifications = content.all.notification;
            $scope.personalNotifications = content.personal.notification;
            $scope.businessNotifications = content.business.notification;
        }).error(function(data, status, headers, config) {
            // log error
        });
}).error(function (a, b, c) {
        console.log(a, b, c);
});

1 个答案:

答案 0 :(得分:0)

尝试在范围变量

之后使用 $ scope.apply()
$scope.notifications = content.all.notification;
$scope.personalNotifications = content.personal.notification;
$scope.businessNotifications = content.business.notification;
$scope.$apply();