如何比较angularjs中两个不同函数声明的两个不同对象数组?

时间:2017-06-22 11:55:36

标签: javascript angularjs

var app2 = angular.module("webApp2", [])
    .controller("webCtrl2", function ($scope, $state, $http) {
        console.log("hi");
        $scope.username = $state.params.username;
        console.log("shbsdjh" + $scope.email)
        $scope.userId = $state.params.userid;
        $scope.requests = [];
        var addedList = [];

        //Getting requests list:
        $http.get("http://192.168.2.3:3000/userslist")
            .then(function (response) {
                console.log("hi", JSON.stringify(response));
                $scope.requests = response.data;
            }, function (response) {
                console.log("error" + response);
            });

        $scope.addfrnd = function (reqname, index) {
            console.log("shgsgh" + reqname);
            var data = {
                userId: $scope.userId,
                requestname: reqname,
                username: $scope.username
            }
            var req = {
                method: 'POST',
                url: 'http://192.168.2.3:3000/friendrequests',
                data: data
            }
            $http(req).then(function (response) {
                console.log("saghdha" + JSON.stringify(response.data));
                //..........................................................................................
                //Gettind added list
                $http.get("http://192.168.2.3:3000/sendfriendrequests/" + $scope.username)
                    .then(function (response) {
                        console.log("added list" + JSON.stringify(response));
                        addedList = JSON.stringify(response.data.username);
                        console.log("addedlist" + addedList)
                    }, function (response) {
                        console.log("error" + response);
                    });
                //..........................................................................................

            }, function (response) {
                console.log(response);
            });
        }
        console.log("uname" + addedList);
        $scope.logoutFn = function () {
            $state.go("signup");
        }

    });

我正在使用聊天应用程序。在我获取用户列表并使用API​​发送请求列表。在用户列表API中,人员的数组列表将获取并发送请求API,我发送请求的人员的数组列表现在。现在我必须比较这两个包含对象的数组,以便将那些人移除到用户列表中发送请求的那些人。我在实现angularjs中的代码时遇到了问题,以便比较在两个不同函数中声明的这两个数组。请帮我.. 这是我的javascript代码:

1 个答案:

答案 0 :(得分:0)

试试这个

angular.forEach(arr1, function(value1, key1) {
        angular.forEach(arr2, function(value2, key2) {
            //Comparison logic
        });
    });