簡體   English   中英

AngularJS UI Bootstrap Modal將對象傳遞給控制器

[英]AngularJS UI Bootstrap Modal passing object to controller

我正在嘗試使用resolve將對象傳遞給模式控制器,但它似乎無法正確傳遞。 我可以在傳遞對象之前立即console.log對象,但是嘗試將其記錄在模式控制器中只是顯示它是未定義的。 我看過其他相關的問題,但是從給出的答案中看不出我在做什么。 這是我的控制器:

app.controller('BlogController', ['$scope', '$http', '$modal', function($scope, $http, $modal){

    $scope.blogEntry = {}; // Place holder for data (blog entry)

    $scope.editBlogEntry = function(blogEntry) {
        $scope.blogEntry = blogEntry;
        $scope.editModal = $modal.open({
           templateUrl: '/resources/partials/editBlogModal.html',
            controller: 'EditBlogController',
            size: 'lg',
            resolve: {
                blogEntry: function() {
                    console.log($scope.blogEntry);  //this shows the object
                    return $scope.blogEntry;
                }
            }
        });
    };
}]);

app.controller('EditBlogController', ['$scope', '$http', '$modalInstance', function($scope, $http, $modalInstance, blogEntry){
    $scope.blogEntry = blogEntry;
    console.log($scope.blogEntry);  //undefined
}])

誰能看到我所缺少的嗎? 非常感謝您的幫助!

您忘記將blogEntry添加為傳遞給模式控制器的數組中的最后一個字符串。

app.controller('EditBlogController', ['$scope', '$http', '$modalInstance', function($scope, $http, $modalInstance, blogEntry)
                                                                     HERE ^

幫自己一個忙,並使用ng-annotate ,它將消除對這種難看的數組語法的需要,從而避免了此類錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM