gpt4 book ai didi

jquery - 无法从 Controller 传递已解析的参数

转载 作者:可可西里 更新时间:2023-11-01 16:42:36 24 4
gpt4 key购买 nike

页面根本没有加载。我正在尝试解析 HTTP 服务。

我的工厂:

app.factory("search", function($q, $http, $cookieStore){
return {
getMessage: function(){
//return $q.when("Response");
console.log("Cookie --> ".$cookieStore.get("sId"));
var promise = $http.post('tpl/processors/process-contacts.php', {sid : $cookieStore.get("sId")}).then(function(response) {
return response.data;
});
return promise;
}
}
});

我解决的问题:

  .state('app.mail.compose', {
url: '/compose',
templateUrl: 'tpl/mail_new.php',
reloadOnSearch: true,
resolve: {
searchVal: ['search', function (search) {
return search.getMessage(); // not then
}]
}
})

我的 Controller :

 app.controller('SmsNewCtrl', ['$scope','$http','$cookieStore','$stateParams','searchVal',         function($scope, $http, $cookieStore,$stateParams,searchVal,transformRequestAsFormPost) {
$scope.sId = $cookieStore.get("sId");
//console.log("Inbox Type : "+ $stateParams.inboxType );
console.log("Cookie Call inside SmsNewCtrl: ",$cookieStore.get("sId"));


$scope.contacts = searchVal;
console.log("Contacts from Search Factory :" + $scope.contacts);


$scope.mail = {
to: '',
content: ''
}

}]);

之前,我曾经在我的 Controller 中执行 http 调用。到那时一切正常,但页面首先加载,数据随后出现。所以我想通过在 Controller 外部进行 http 调用来解析数据。我是 Angular 的新手,仍在学习中,如果我的方法有误,请告诉我,或者让我知道在 Controller 外部执行 http post 并解决的最佳方法。

最佳答案

我写了一个简单的例子,它是有效的: http://jsbin.com/nuzaqugofu/1/edit?html,js,console

按照我做的方式尝试,并不断添加越来越多的代码,直到它不再工作为止。然后你就会知道是什么导致了问题。

关于jquery - 无法从 Controller 传递已解析的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27501579/

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