I am trying to do a http post using AngularJS but angular is not converting my $scope variable to JSON.
Here is my code:
$http({
method: "POST",
url: "/Account/Login",
data: $scope
})
Which results in the request POST message having
"$SCOPE"
but if I change it to output any of my scope properties, it is sending the message with correct properties, e.g.:
$http({
method: "POST",
url: "/Account/Login",
data: { email: $scope.email, password: $scope.password }
})
Which results in the request POST message having
{"email":"[email protected]","password":"asd"}
Do I always have to wrap my requests like this? Or is there a way to tell AngularJS to send all properties on scope? Any Pro's / Con's?
$scope. Use an inner object like$scope.datawhich hasdata.emailanddata.password. It does say to do this in the manual becausengIfandngRepeatwill isolate your primitive scope variables.