I am using factory to retrieve to JSON data from the server thus:
ForumsFactory.factory('ReadFactory', function ($http) {
    var forumsFactory = {};
 forumsFactory.itIs = function () {
        var me = $http.get('/Forums/WhoIsLoggedIn');
        return me;
    };
    forumsFactory.addSpyUser = function (userid, postid) {
        if (userid != null) {
            User = { UserID: userid, PostId: postid }
            var result = $http.post('/Threads/SpyUser', User);
            return result;
        }
    }
forumsFactory.getPostById = function (postid) {
        var result = $http.get('/Read/PostsByPostId/' + postid);
        return result;
    };
 return forumsFactory;
});

And am handling it with a my controller thus:
ForumsApp.controller('ReadCtrl', 
    function ($scope, $stateParams, ReadFactory) { 
 ReadFactory.itIs().success(function (me) {
            $scope.who = me
            console.log($scope.who)
            ReadFactory.addSpyUser('7282541d-91e0-4a3c-bf62-31f4cf3ab5fc', 
$stateParams.postId).success(function (data2) {
                console.log(data2)
            })
        })

ReadFactory.getPostById($stateParams.postId).success(function (data) {
            $scope.post = data;
            
        })   });

and finally render it to a view thus:
<div class="panel panel-forums" ng-repeat="p in post">
    <div class="panel-heading">
        <h3 class="panel-title" style="color:#fff">{{p.Title}}</h3>
    </div>
    <div class="panel-body" ng-bind-html="p.Body">
        
    </div>
</div>

The problem is that every thing comes out fine except that when I log any 
of those data returned, they are display in pairs.

addSpyUser() performs a http.post but twice thereby inserting data twice to 
my database.
Please what have I done wrong.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to