angularjs-ng-repeat

ng-repeat: access key and value for each object in array of objects

丶灬走出姿态 提交于 2019-11-27 17:48:02
I have an array of objects and I am using an ng-repeat to iterate over them, which is easy. The array looks something like this: $scope.steps = [ {companyName: true}, {businessType: true}, {physicalAddress: true} ]; And my ng-repeat attribute looks like: <div ng-repeat="step in steps"> ... </div> In each iteration, step is equal to one of the objects, as expected. Is there anyway to access both the key and the value of the step object? So that I could do something like this: <div ng-repeat="(stepName, isComplete) in steps"> ... </div> Where stepName == 'companyName' and isComplete == true . I

Angularjs if-then-else construction in expression

大憨熊 提交于 2019-11-27 17:33:36
Can I somehow use if-then-else construction (ternary-operator) in angularjs expression, for example I have function $scope.isExists(item) that has to return bool value. I want something like this, <div ng-repeater="item in items"> <div>{{item.description}}</div> <div>{{isExists(item) ? 'available' : 'oh no, you don't have it'}}</div> </div> I know that I can use function that returns string, I'm interesting in possibility of using if-then-else construction into expression. Thanks. Andre Goncalves Angular expressions do not support the ternary operator before 1.1.5, but it can be emulated like

How to catch memory leaks in an Angular application?

China☆狼群 提交于 2019-11-27 17:23:50
I have a webapp written in AngularJS which basically polls an API to two endpoints. So, every minute it polls to see if there is anything new. I discovered that it has a small memory leak and I've done my best to find it but I'm not able to do it. In the process I've managed to reduce the memory usage of my app, which is great. Without doing anything else, every poll you can see a spike in the memory usage (that's normal) and then it should drop, but it's always increasing. I've changed the cleaning of the arrays from [] to array.length = 0 and I think I'm sure that references don't persist so

How to achieve pagination/table layout with Angular.js?

别说谁变了你拦得住时间么 提交于 2019-11-27 17:13:15
Let's say I receive an object literal with 15+ objects and I need to display them in a nice layout (not all in a row), what is the most efficient method for controlling when the line should break/page should end? Right now I'm using ng-repeat on table row's, and the result is a long thin table with one column. Edit for clarification. Could have objects within objects/more params. Here is my object: $scope.zones = [ {"name": "Zone 1", "activity": "1"}, {"name": "Zone 2", "activity": "1"}, {"name": "Zone 3", "activity": "0"}, {"name": "Zone 4", "activity": "0"}, {"name": "Zone 5", "activity": "0

Show hidden div on ng-click within ng-repeat

我的梦境 提交于 2019-11-27 16:55:12
I'm working on an Angular.js app that filters through a json file of medical procedures. I'd like to show the details of each procedure when the name of the procedure is clicked (on the same page) using ng-click. This is what I have so far, with the .procedure-details div set to display:none: <ul class="procedures"> <li ng-repeat="procedure in procedures | filter:query | orderBy:orderProp"> <h4><a href="#" ng-click="?">{{procedure.definition}}</a></h4> <div class="procedure-details"> <p>Number of patient discharges: {{procedure.discharges}}</p> <p>Average amount covered by Medicare: {

shuffle array in ng-repeat angular

隐身守侯 提交于 2019-11-27 15:20:40
I'm creating a quiz and every time I start the quiz I want to shuffle the questions, so that they won't appear in the same order every time. I have this in my html code: <div ng-repeat="question in questions | filter:ids | orderBy:randomSort"> <div id="question">{{question.question}}</div><img id="nextImg" ng-src="../app/img/next.png" ng-click="next()" /> <img class="quizImg" ng-hide="{{question.image}}==null" ng-src="{{question.image}}" /> <div class="answer" ng-repeat="answer in question.answers"> <input type="radio" ng-click="checked(answer)">{{answer.answer}} </div> <!--input id=

ng-repeat a single element over nested objects

早过忘川 提交于 2019-11-27 14:59:31
问题 Say I have an object with keys corresponding to products and values corresponding to objects which in turn have keys corresponding to price points at which those products have sold, and values corresponding to amount sold. For example, if I sold 10 widgets at $1 and 5 widgets at $2, I'd have the data structure: { 'widget': {'1': 10, '2': 5} } I'd like to loop over this structure and generate rows in a table such as this one: thing price amount --------------------- widget $1 10 widget $2 5 In

ng-repeat specify a starting index

十年热恋 提交于 2019-11-27 14:15:55
How can I specify an index where an ng-repeat directive is going to start instead of zero? I have a set of results and I just need to specify the starting one, which is different from zero. No need to code anything, angular has done this with the existing built-in limitTo filter. Just use a negative limit. From the docs for the limit argument: The length of the returned array or string. If the limit number is positive, limit number of items from the beginning of the source array/string are copied. If the number is negative, limit number of items from the end of the source array/string are

How to show a message when filter returns nothing in ng-repeat - AngularJS

青春壹個敷衍的年華 提交于 2019-11-27 13:42:49
问题 I would like to show one div(message) when no items returned on filter(ng-repeat). Filter is happening based on select box (ng-model). And there are no results for some select options, at that time user should be able to read a message at same place. Can I use ng-show/hide here? How? Thanks, 回答1: You can also save your filtered array in a variable and then use that variable inside the ng-show expression: <select ng-model="shade" ng-options="shade for shade in shades"></select><br> <ul> <li ng

angularjs text area character counter

独自空忆成欢 提交于 2019-11-27 12:33:51
Hi I have a characeter counter for a text area. My problem is that it doesn't count spaces or linebreaks. How do I make it so that it does so? <div class="controls"> <textarea rows="4" cols="50" maxlength="1500" data-ng-minLength="1" data-ng model="createprofilefields.description" required highlight-on- error></textarea> <br /> <!--counter--> <span class="form-help">{{1500-createprofilefields.description.length}} Characters</span> </div> It's because angularJS automatically trimmed your model. If you're using angularJS 1.1.1 or newer, add ng-trim="false" to textarea . Working example: http:/