简体   繁体   English

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

[英]How to compare two different arrays of objects declared in two different functions in 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"); } }); 

Iam working with chat application.Here Iam getting userslist and send request list using APIs.In the userslist API,an array list of people will get and in send request API,an array list of people to those I have send the request will be present.Now I have to compare the these two arrays containing objects inorder to remove the people to those the request is send in the userslist.Iam strucked at implementing the code in angularjs for comparison of these two arrays declared in two different functions.Please help me.. This is my javascript code: 我正在使用聊天应用程序。这里我正在使用API​​获取用户列表和发送请求列表。在用户列表API中,将获得人员列表,在发送请求API中,将显示我已发送请求的人员列表现在,我必须比较这两个包含对象的数组,以便将用户移到用户列表中发送的请求中.Iam震惊于在angularjs中实现代码,以比较在两个不同函数中声明的这两个数组。请帮帮我..这是我的JavaScript代码:

Try this 尝试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM