我有一个服务
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"
但是 Angular 代码控制台向我展示了
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": "\""
}
为什么数据不是以字符串形式出现的?