Monday, 26 August 2013

Angular Service returns String as dictionary

Angular Service returns String as dictionary

I have a service as
angular.module('inviteService', ['ngResource']).factory('Invite', function
($resource) {
return $resource('/invite');
});
and my controller is
$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;
});
and relevant directive code as
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);
When I run the code, I see in Chrome Network tab the response as
"You are already on our invite list"
But the Angular code console shows me
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":"\""}}
Why is that data is not coming as string?

No comments:

Post a Comment