gpt4 book ai didi

javascript - $state.go 之后在 Controller 之间传递数据?

转载 作者:行者123 更新时间:2023-11-28 18:39:39 25 4
gpt4 key购买 nike

假设我有一个位于商店 Controller 中的商品列表。然后用户单击其中一个项目,它使用另一个 Controller ,如何获取项目 Controller 中的项目?

.controller('store', function($scope,$http,$state) {

$http({
method: 'GET',
url: $rootScope.hostname + '/api/products',
}).then(function successCallback(response) {
$scope.items = response.data.product;

}, function errorCallback(response) {
alert(response.data)
});

$scope.GoItem = function(data){
//data
$state.go('app.item');
}
})

.controller('item', function($scope,$http) {
//how to get the data here?
})

最佳答案

编辑:我问错了。由于您尝试在 Controller 之间传递,因此您有几个选择。

  1. 使用$rootScope。此范围在您的整个应用中共享。
  2. 使用服务。将您的 http 调用存储为函数。

关于javascript - $state.go 之后在 Controller 之间传递数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36337103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com