向大家问好。
我正在尝试获取从 Angular 上的 $http 返回的数据。我创建了一个工厂:
.factory('MyFactory', function($http, SKURL) {
return {
all: function(my_data) {
return $http({
method: 'POST',
url: SKURL.url,
data: "data=" + my_data,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
}
}
})
Run Code Online (Sandbox Code Playgroud)
然后,在控制器中,我写道:
var n = MyFactory.all(my_data);
Run Code Online (Sandbox Code Playgroud)
当我看到 console.log(n) 时,我看到返回的对象是一个 Promise: Promise {$$state: Object}。当我展开对象时我看到了数据。但是,当我尝试 get n.$$state.value.data 时,我得到了undefined。如何获取返回的数据$http?
我正在调整一个例子来上传一个图像到imgur.该示例使用curl,我使用guzzle ^ 6.1.卷曲的例子是:
<html>
<h3>Form</h3>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
Image (< 50kb): <input type="file" name="upload" /><br/>
ClientID: <input type="text" name="clientid" /><br/>
<input type="submit" value="Upload to Imgur" />
</form>
</html>
<?php
if (empty($_POST['clientid']) || @$_FILES['upload']['error'] !== 0 || @$_FILES['upload']['size'] > 50000) {
exit;
}
$client_id = $_POST['clientid'];
$filetype = explode('/',mime_content_type($_FILES['upload']['tmp_name']));
if ($filetype[0] !== 'image') {
die('Invalid image type');
}
$image = file_get_contents($_FILES['upload']['tmp_name']);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( …Run Code Online (Sandbox Code Playgroud) 我有一个数组,如:
var db = [{
"words": ["word1a", "word1b", "word1c"],
"answer": "answer1"
}, {
"words": ["word2a", "words2b"],
"answer": "answer2"
}]
Run Code Online (Sandbox Code Playgroud)
我在node.js上使用lodash来检查数组中的值.我想搜索单词并返回回复.例如,如果我搜索"word1a",则响应为"answer1"
我尝试:
var e = _.find(db, function(o){
o.words === "say"
});
console.log(e);
Run Code Online (Sandbox Code Playgroud)
但我找不到结果;
显然,我得到了未定义,因为我正在比较一个确切的值.我怎样才能获得价值?