Search Posts

Category: arrays

How can I use angular arrays/ lists effectively

So I am building analytics for a site. I am pulling data from an a rest API and feeding it into an angular front end. I have arrays like these in my .component.ts file: Array 1 this.statsPassed24Hrs = [ {‘Description’: ‘Total A’, ‘Count’: this.a}, {‘Description’: ‘Total B’, ‘Count’: this.b}, {‘Description’: ‘Total C’, ‘Count’: this.c}, {‘Description’: ‘Total D’, ‘Count’: this.d}, {‘Description’: ‘Total E’, ‘Count’: this.e} ]; Array 2 this.statsPassed7Days = [ {‘Description’: ‘Total A’, ‘Count’: this.aPassed7Days}, […]

Concat arrays in ES5 style . Merge arrays into one [duplicate]

This question already has an answer here: Merge/flatten an array of arrays in JavaScript? 57 answers I have to merge chunk of arrays into single array with array of objects in Angularjs. my input array will be like: [ [ { “title”: “asd”, “description”: “asd” }, { “title”: “asz”, “description”: “sd” } ], [ { “title”: “ws”, “description”: “sd” }, { “title”: “re”, “description”: “sd” } ], [ { “title”: “32”, “description”: “xxs” }, { […]

Multiple series in Highcharts

Request help for the Scenario. Say i have an array of categoryid as controller.dataList = [ {pvalue:10,nvalue:20,categoryid: 1,date:”12-03-1998″}, {pvalue:40,nvalue:40,categoryid: 2,date:”13-03-1998″}, {pvalue:60,nvalue:150,categoryid: 3,date:”14-03-1998″}]. Now for each catergoryid i want a high chart series of pvalue and nvalue.So in AngularJs code i am calling a common method to generateChart like: function generateChart() { var localDl = angular.copy(controller.dataList); var NValueList = localDl.map(function(obj) { return {x: moment.tz(objDate, “GMT”).valueOf(), y: Math.round(obj.nvalue), data: angular.copy(obj)}; }); var PvalueList = localDl.map(function(obj) { return […]

How to increment a variable when something is true

I am creating an application using angularJS and I am stuck trying to get a couple variables to increment when a condition is true. I have a object that has info like id: 1 payment: pending id: 2 payment: paid Here is my code var currentIndex = 0; $scope.unpaid = 0; $scope.paid = 0; const getSessions = () => { loginService.getUser().then((response) => { var user_id = response.data.id; console.log(“getUser returning this => “, response.data); loginService.getUserSessions(user_id).then((response) => […]

How to find the indexof of an object in javascript [duplicate]

This question already has an answer here: indexOf method in an object array? 27 answers Get the index of the object inside an array, matching a condition 13 answers I am having an array of objects in which i would like to find the index of the selected object when i used the indexOf i am getting the value as -1 can anyone tell me how to find the indexOf of an object in javascript […]

how can I get child elements in angularjs

I’m making a multi-select “drop-down” and I want to disable the category and style it differently in my “drop-down”. so I got the select element and I want to make those children that are category disable. how can I get the children to do this. so far I’ve done this: “use strict”; var app = angular.module(“myApp”, []); app.controller(“myCtrl”, function($scope, $http) { $scope.datas = [{ “item”: “South Korea”, “category”: “Asia”, “flag”: false }, { “item”: “England”, […]

not able to save complete image in database using angularjs [duplicate]

This question already has an answer here: File Upload using AngularJS 28 answers In code, I’m uploading image in tables and i need to store these images in database. So 1st converting images to base64 format and then storing in the database as blob. following same exact steps as given in below link and able to save image in database. How to convert image to byte array using javascript only to store image on sql […]

How to parse a string to array in js

I have an a string like the following, var x = “[{“k”:”1″}]”; console.log(x[0].K); I ant hange this string sine I am getting from the server.Its out of my control. I want to display the ‘k’ value and when I onsole it,got Uncaught SyntaxError: Unexpected identifier I know,it beasuse of the ‘double quotes’ inside and outside of the array. It is not even allowing me to parse it. So,I thought 1)Replace “[ and ]” as ‘[ […]

AngularJS – Array as filter

How can I setup a filter in an ng-repeat that use strings and an array of strings? HTML <div ng-repeat=”type in types| orderBy : ‘name’ | filter:{typology:currTipology}” JavaScript var myData = [‘string_1’, ‘string_2’, [‘string_3’, ‘string_4′]]; I’ll use a button for every myData entry to assign the string value to ┬┤currTipology`. Source: AngularJS

Array for displaying multiple stats for multiple time periods – how to avoid repeating your code

So I have had to create multiple arrays in my .ts file. Than I loop through them in my html code. But the repeatation all looks very wrong. Is there any better way of doing this? See the code bellow : private arrayData1() { this.array = [ {‘Description’: ‘Stat 1’, ‘Count’: this.totalX}, {‘Description’: ‘Stat 2’, ‘Count’: this.totalY}, {‘Description’: ‘Stat 3’, ‘Count’: this.totalZ}]; } private arrayDataForPassed7Days() { this.arrayPassed7Days = [ {‘Description’: ‘Stat 1’, ‘Count’: this.totalA}, {‘Description’: […]

Next Page »