Search Posts

Category: arrays

Removing duplicate value from array of object

I have created angularjs app in which I have made quiz module in which question 1-5 has same description then question 6-7 has same description so I have save same description to each question and display them using one by one on next button. now the functionality is change I want to display on single page so I have used ng-repeat now the problem is the question description is also repeating so same description is […]

AngularJs array inside of array display in textarea

I have this kind of data $scope.data = [{ “production_list”: [ {“product”: “googlen”}, {“product”: “stackoverflown”}, {“product”: “angularn”} ] }] How can I display it in textarea like this? <textarea> google stackoverflow angular </textarea> What I tried is <tr ng-repeat=”list in data”> <td> <textarea ng-repeat=”x in data.production_list”> {{x.product}} </textarea> </td> </tr> The output is <textarea> google </textarea> <textarea> stackoverflow </textarea> <textarea> angular </textarea> And is this a possible to have an increment? Because instead of ng-repeat […]

get element array from input text in angular scope

I use charjs in angular. I will create chart from dinamic data. How make array in $scope.fruits.datas from value input text persen ? HTML <input type=”text” name=”persen” id=”textinput2″ readonly style=”font-size: 20px;text-align:center; color:aliceblue; background:#60222A; ” /> JS function calcscore(){ var score = 0; var persen=0; $(“.calc:checked”).each(function(){ score+=parseInt($(this).val(),10); persen=((score/17)*100).toFixed(2); }); $(“input[name=sum]”).val(score) $(“input[name=persen]”).val(persen)} }); ANGULAR app.controller(‘MyController’, function ($scope) { $scope.fruits = { labels: [“a”, “b”], datas : [9,3], color: [“#FEBD01″,”#FF8C00”], }; Source: AngularJS

Update JavaScript object property value, push to array, and then set back to original value

I am trying to update a Javascript object value so that I can push it into an new array for filtering, but I then need to reset the object’s property value back to its original value for when the user removes the filter (the user can toggle it on and off). I have tried everything I have seen here on stackoverflow and nothing has seemed to work. I have tried: if (ctrl.dataArray.indexOf(row) === -1) { […]

How to create a key indexed array in javascript

I have a blank array similar like: WO_Attribute: [] (0) I also have key : 363270 and array: { wosetid: “363612”, woattrvalueid: 212122, woattrvalue: “testing”, woattrid: 6842 } How can I create similar array as follows: “WO_Attribute”: { “363270”: [ { “wosetid”: 363270, “woattrvalueid”: 5160601, “woattrvalue”: “testing”, “woattrid”: 1602 } ] } I used the following method but its not working if WO_Attribute is blank array: let WO_Attribute = []; let resArr = []; let […]

How to get parent object value by using child array key value using Angular.js/Javascript

I need one help. I need to retrieve the parent object value if any child key value is there using Angular.js or Javascript. I am explaining my code below. $scope.data = [{ “parentdes”: “Parent description1”, “parent_id”:”1″ “childdes”: [{ “des”: ‘chile description11’, “sub_id”:”11″ “subchilddes”: [{ “des”: ‘subchild des111’, “sub_sub_id”:”111″ }] }, { “des”: ‘chile description12’, “sub_id”:”12″ “subchilddes”: [{ “des”: ‘subchild des112’, “sub_sub_id”:”112″ }] }] }, { “parentdes”: “Parent description2”, “parent_id”:”2″ “childdes”: [{ “des”: ‘chile description21’, “sub_id”:”21″ […]

Button Functionality in angular js

I am currently having an issue with my button running a function in my angular js web app. Below is the HTML Code : <div ng-controller=”myTeamCtrl”> <nav class=”navbar navbar-inverse”> <div class=”container-fluid”> <div class=”navbar-header”> <a href=”#” class=”navbar-brand”>TNF</a> </div> <ul class=”nav navbar-nav”> <li class=”active”><a href=”#/welcome”>Home</a> </li> <li><a href=”#/myTeam”>Players Transfer</a> </li> <li><a href=”#/mySquad”>My Squad</a> </li> <li><a href=”#/rules”>Rules</a> </li> <li><a href=”#/league”>THE LEAGUE</a> </li> <li><a href=”#/stats”>Statistics</a> </li> <li ng-click=”logout()” ><a href=”#”>Logout</a> </li> </ul> </div> </nav> <div class=”container”> <div class=” navbar […]

Firebase AngularJS array map()

I have multiple firebase items that I am looping through and they have name, categoryId, lat, lon. I am trying to calculate a distance from 2 lat,lon (one is the one in firebase), the other is the user’s location. All of this is fine, and I can calculate it fine too. However, how do I inject/map the new variable into the firebase array that I am subscribed to? this.categoryId = this.navParams.get(‘categoryId’); afoDatabase.list(‘/list’, {query: { orderByChild: […]

How to delete multiple checked items from a list in angular

I have the following string; $scope.Array=”5678,9876,0988″ I am displaying it in my html as follows: <li ng-repeat=”ArrayItem in Array.split(‘,’)”> <input type=”checkbox” > {{Zip}} </li> this displays all the string items separately along with a check box. I would like to know how to select multiple items from the list on the UI, and on the press of delete, delete these items from Array. e.g. check 5678, 9876, and click Delete. The Array would now only […]

JavaScript Checking Array Out of Bounds

I have a matrix as arena and a small matrix as player. With keys user can move around. move(pos) takes argument and inside checks if(pos==”down”) if (!collide(pos)) player.pos.y++; And collide works like if(pos==”down”) for (i = 0; i < player.matrix.length; i++) { for (j = 0; j < player.matrix[i].length; j++) { if ((player.matrix[i][j] && arena[player.pos.y + i + 1][player.pos.x + j]) != 0) result = true; } } This woks perfect till you come edge […]

Next Page »