AngularJS UI Bootstrap 模态传递对象到控制器
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,这将消除对这种丑陋的数组语法的需求,从而避免此类错误。
我正在尝试通过 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,这将消除对这种丑陋的数组语法的需求,从而避免此类错误。