angularjs-ng-repeat

Angular.js ng-repeat across multiple elements

廉价感情. 提交于 2019-11-27 06:31:23
This question has been partly addressed here: Angular.js ng-repeat across multiple tr's However that is just a work-around really, it doesn't actually address the core issue, which is: how can one use ng-repeat across multiple elements without a wrapper? For example, jquery.accordion requires you to repeat an h3 and div element, how could one do this with ng-repeat? Igor Minar We now have a proper support for this, please see: AngularJs Commmit with this change you can now do: <table> <tr ng-repeat-start="item in list"> <td>I get repeated</td> </tr> <tr ng-repeat-end> <td>I also get repeated<

AngularJS ng-repeat handle empty list case

十年热恋 提交于 2019-11-27 05:49:05
I thought this would be a very common thing, but I couldn't find how to handle it in AngularJS. Let's say I have a list of events and want to output them with AngularJS, then that's pretty easy: <ul> <li ng-repeat="event in events">{{event.title}}</li> </ul> But how do I handle the case when the list is empty? I want to have a message box in place where the list is with something like "No events" or similar. The only thing that would come close is the ng-switch with events.length (how do I check if empty when an object and not an array?), but is that really the only option I have? Artem

how to use animation with ng-repeat in angularjs

风格不统一 提交于 2019-11-27 05:39:09
问题 I have a list which I iterate over by using ng-repeat: and the user can interact with thte list items by using up-arrow and down-arrow icons and on click of them i simply change the order of the element in the "list" this is what angular suggests change the model and the changes automatically reflect in the view. <div ng-repeat="item in list"> {{item.name}} <div class="icon-up-arrow" ng-click="moveUp($index);"></div> <div class="icon-down-arrow" ng-click="moveDown($index);"></div> </div>

Using ng-repeat to generate select options (with Demo)

百般思念 提交于 2019-11-27 05:38:59
controller: $scope.send_index = function(event, val){ console.log(val); $scope.variable = 'vm.areas['+val+'].name'; console.log( $scope.variable ); }; and this is in the view: <select ng-model="vm.areas"> <option ng-repeat="area in vm.areas" ng-value="area" id="{{area}}" ng-click="send_index($event, $index)">{{area.name}} </select> <input value="{{variable}}"> where "vm" is my model. Expression inside of an expression (Angular) my problem is that i need to have an {{array[]}}, with the index as another expression, e.g: {{Array[{{val}}]}}. Already tryed this: $scope.variable = ''+'vm.areas['

AngularJS: ng-model inside ng-repeat?

泪湿孤枕 提交于 2019-11-27 05:36:45
问题 I'm trying to generate form inputs with ng-repeat. Note: 'customFields' is an array of field names: ["Age", "Weight", "Ethnicity"]. <div class="control-group" ng-repeat="field in customFields"> <label class="control-label">{{field}}</label> <div class="controls"> <input type="text" ng-model="person.customfields.{{field}}" /> </div> </div> What is the best/correct way to set 'ng-model'? I would like to send it to the server as person.customfields.'fieldname' where fieldname comes from 'field

How to remove elements/nodes from angular.js array

青春壹個敷衍的年華 提交于 2019-11-27 05:00:46
问题 I am trying to remove elements from the array $scope.items so that items are removed in the view ng-repeat="item in items" Just for demonstrative purposes here is some code: for(i=0;i<$scope.items.length;i++){ if($scope.items[i].name == 'ted'){ $scope.items.shift(); } } I want to remove the 1st element from the view if there is the name ted right? It works fine, but the view reloads all the elements. Because all the array keys have shifted. This is creating unnecessary lag in the mobile app I

AngularJS sorting rows by table header

我与影子孤独终老i 提交于 2019-11-27 05:00:10
问题 I have four table headers: $scope.headers = ["Header1", "Header2", "Header3", "Header4"]; And I want to be able to sort my table by clicking on the header. So if my table looks like this H1 | H2 | H3 | H4 A H D etc.... B G C C F B D E A and I click on H2 my table now looks like this: H1 | H2 | H3 | H4 D E A etc.... C F B B G C A H D That is, the content of each column never changes, but by clicking on the header I want to order the columns by, the rows will reorder themselves. The content of

ng-repeat unknown number of nested elements

不问归期 提交于 2019-11-27 04:38:13
问题 I'm wondering if there is a simple solution to this type of problem. I have an object comment, which can in turn contain comments, and those comments can also contain comments ...and this can go on for a unknown number of cycles. Here is an example of the data structure: var comment = { text : "", comments: [ { text: "", comments : []}, { text: "", comments: [ { text: "", comments : []}, { text: "", comments : []} { text: "", comments : []} ]} ] } Lets say for 2 levels of comments I would

AngularJs Remove duplicate elements in ng-repeat

泪湿孤枕 提交于 2019-11-27 03:39:09
I have one dictionary which is stored in field_detail <li ng-repeat = "field in field_detail">{{field.displayName}}</li> Now I dont want to include duplicate displayName of field_detail , what filter should I use? Just create a filter that gets the unique values, probably by a key. Something like this ought to do (I didn't test this at all, so I'll leave that business to you, this is just to give you an idea): app.filter('unique', function() { return function(collection, keyname) { var output = [], keys = []; angular.forEach(collection, function(item) { var key = item[keyname]; if(keys.indexOf

How to use “ng-repeat” within template of a directive in Angular JS?

爷,独闯天下 提交于 2019-11-27 03:16:30
I'm new to Angular JS and I am trying to create a custom directive that will be used as below: <div linkedlist listcolumns="{{cashAccountsColumns}}"></div> Corrps. controller will be: $scope.cashAccountsColumns = [ {"field": "description", "title": "Description"}, {"field": "owner", "title":"Owner"}, {"field": "currentBalance", "title":"Current Balance" } ]; And the directive code is: return { restrict : 'EA', transclude : false, templateUrl : 'html/linkedlist.html', scope: { listcolumns: "@" }, link : function(scope, element, attrs) { } } template is: <table class="box-table" width="100%">