2
我有一个服务作为角服务返回的字符串作为字典
angular.module('inviteService', ['ngResource']).factory('Invite', function ($resource) {
return $resource('/invite');
});
和我的控制器是
$scope.invite = function() {
console.log("submitting invite for " + $scope.email);
var invite = new Invite();
Invite.save({'email': $scope.email}, function (data) {
console.log('data is: ' + data);
$scope.message.type = 'info';
$scope.message.content = data;
// console.log('controller message' + JSON.stringify($scope.message, null, 2));
// reset email input box
$scope.email = undefined;
});
和相关指令代码
scope.$watch('ngModel', function() {
if (Object.keys(scope.ngModel).length > 0) {
console.log('directive message: ' + JSON.stringify(scope.ngModel));
element.show();
//noinspection JSUnresolvedFunction
$timeout(function() {
//element.empty();
element.fadeOut("slow");
}, 1000);
}
}, true);
当我运行代码,我在Chrome Network tab
看到的回复为
"You are already on our invite list"
但角码控制台显示我
data is: [object Object] notificationController.js:13
directive message:{
"type": "info",
"content": {
"0": "\"",
"1": "Y",
"2": "o",
"3": "u",
"4": " ",
"5": "a",
"6": "r",
"7": "e",
"8": " ",
"9": "a",
"10": "l",
"11": "r",
"12": "e",
"13": "a",
"14": "d",
"15": "y",
"16": " ",
"17": "o",
"18": "n",
"19": " ",
"20": "o",
"21": "u",
"22": "r",
"23": " ",
"24": "i",
"25": "n",
"26": "v",
"27": "i",
"28": "t",
"29": "e",
"30": " ",
"31": "l",
"32": "i",
"33": "s",
"34": "t",
"35": "\""
}
} 这是为什么数据是不是来为字符串?
'console.log(data);'output? – zsong
数据为:{“0”:“\”“,”1“:”Y“,”2“:”o“,”3“:”u“,”4“:”“,”5“ a“,”6“:”r“,”7“:”e“,”8“:”“,”9“:”a“,”10“:”l“,”11“:”r“, “12”:“e”,“13”:“a”,“14”:“d”,“15”:“y”,“16”:“”,“17”:“o” :“n”,“19”:“”,“20”:“o”,“21”:“u”,“22”:“r”,“23”:“”,“24” “25”:“n”,“26”:“v”,“27”:“i”,“28”:“t”,“29”:“e”,“30”:“”,“31 “:”l“,”32“:”i“,”33“:”s“,”34“:”t“,”35“:”\“”} – daydreamer
您可以使用文本/像这样'$ httpProvider.defaults.headers.common ['Accept'] ='text/plain';'? – zsong