angularjs-ng-repeat

OrderBy boolean value with AngularJS ng-repeat

跟風遠走 提交于 2019-11-28 07:18:17
问题 I'd like to be able to sort by whether a variable is true or false. Let's say we have a variable like so: groups = { { name: 'first', value: true }, { name: 'second', value: false }, { name: 'third', value: true }, { name: 'fourth', value: false } } And we can loop through it like so: <div ng-repeat="group in groups"> {{group.name}} {{group.value}} </div> Which will give you the following: first true second false third true fourth false But if I wanted to sort by a boolean value then I could

AngularJS: ng-repeat with dynamic list, without rebuilding entire DOM tree?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 06:46:25
I'm using ng-repeat on a table row with data from a JSON array retrieved from a server. My goal is to have the list update automatically whenever an item is added, removed, or modified on the server, without affecting the unmodified items. In the final implementation, these table rows will also contain bidirectionally bound <input> and <select> elements to send updates back to the server. Some of the available options in the <select> elements will also be generated using ng-repeat directives from another list that may also change. So far, every time a new array comes from the server (currently

Using ng-repeat and ng-class on rows inside a table

假如想象 提交于 2019-11-28 06:40:43
I am using AngularJS and the effect I want to get would be something similar to what this would produce, assuming it would work (which it doesn't). View <tr ng-repeat='person in people' ng-class='rowClass(person)'> <td>.....info about person...</td> <td>.....info about person...</td> <td>.....info about person...</td> </tr> Controller $scope.rowClass = function(person){ ...return some value based upon some property of person... } I realise that this code won't work because person is unavailable to ng-class as it will only be available to objects inside each row. The code is to get the idea of

AngularJS using $sce.trustAsHtml with ng-repeat

穿精又带淫゛_ 提交于 2019-11-28 06:31:40
I'm trying to use $sce.trustAsHtml() with a property of an object in ng-repeat. The result is that the HTML is totally blank. The HTML outputs correctly using ngSanitize though. <div ng-repeat="question in questions"> <p ng-bind-html="$sce.trustAsHtml(question.body)"> </p> </div> I'm on AngularJS v1.3.0-beta.3 by the way. Not sure if there's a bug or I do something wrong. You can't use $sce.trustAsHtml in an expression (unless $sce is a property on the $scope ) because expressions are evaluated in the context of the $scope . The cleanest approach is to use ngSanitize . The second cleanest is

how to use animation with ng-repeat in angularjs

[亡魂溺海] 提交于 2019-11-28 06:16:18
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> Logic in moveUp:- $scope.moveUp= function(position){ var temp=list[position-1]; list[position-1]=list

Angular JS filter not equals

走远了吗. 提交于 2019-11-28 06:07:36
Seems like a very basic question but I can't get the syntax right.. <li class="list-group-item" ng-repeat="question in newSection.Questions | filter:Id != '-1'; " ng-mouseenter="hover = true" ng-mouseleave="hover = false"> <div href="#" editable-text="question.Text">{{question.Text}}</div> </li> All I want is to show all the questions where id is NOT -1. What am I doing wrong. Thanks! Michael Rose The syntax is just a little off, try: <li class="list-group-item" ng-repeat="question in newSection.Questions | filter:{ Id: '!-1'}" ng-mouseenter="hover = true" ng-mouseleave="hover = false"> <div

AngularJS: ng-model inside ng-repeat?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 05:54:43
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 in customFields'. <div ng-app ng-controller="Ctrl"> <div class="control-group" ng-repeat="field in

ng-repeat groupBy date field per day

試著忘記壹切 提交于 2019-11-28 05:54:37
问题 I am trying to groupBy a date which is a JS date object. I want to group the data per day. Any ideas how I can do this in a view? $scope.data = { messages: [ { date: new Date(1432811030 * 1000), message: 'Some text 01' }, { date: new Date(1432731600 * 1000), message: 'Some text 02' }, { date: new Date(1432819703 * 1000), message: 'Some text 03' } ] }; And in my view I use: <div ng-repeat="(key, value) in data.messages | groupBy: 'date'"> <div>{{ key }}</div> <div ng-repeat="message in value">

Angularjs templateUrl fails to bind attributes inside ng-repeat

冷暖自知 提交于 2019-11-28 05:38:22
问题 I'm using directive to display html snippets. And templateUrl inside the directive, to be able to include snippets as html file. The directive does not work, if I try to call inside a builtin ng-repeat directive ({{snip}} is passed as is, without substitute): div ng-repeat="snip in ['snippet1.html','snippet2.html']"> <my-template snippet="{{snip}}"></my-template> </div> For reference, here is the directive: app.directive("myTemplate", function() { return { restrict: 'EA', replace: true, scope

dynamically adding directives in ng-repeat

寵の児 提交于 2019-11-28 05:02:06
I am trying to dynamically add different directives in an ng-repeat however the output is not being interpreted as directives. I've added a simple example here: http://plnkr.co/edit/6pREpoqvmcnJJWzhZZKq Controller: $scope.colors = [{name:"red"}, {name: "blue"}, {name:"yellow"}]; Directive: app.directive("red", function () { return { restrict: 'C', template: "RED directive" } }); Html: <ul> <li ng-repeat="color in colors"> <span class="{{color.name}}"></span> </li> </ul> How do I make angular pick up the directive specified in the class that is output via ng-repeat? I know this is an old