繁体   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