angularjs-ng-repeat

ng-repeat with track by and filter and orderBy not working

自作多情 提交于 2019-11-30 08:04:06
I have this code. http://jsfiddle.net/0tgL7u6e/ JavaScript var myApp = angular.module('myApp',[]); function MyCtrl($scope) { $scope.nameFilter = ''; $scope.contacts = [ {name: 'GHI'}, {name: 'DEF'}, {name: 'ABC'}, {name: 'JKL'} ]; } View <div ng-controller="MyCtrl"> <div><input type="text" ng-model="nameFilter" placeholder="Search..." /></div> <p ng-repeat="contact in contacts track by $index | filter: nameFilter | orderBy: name">{{ contact.name }}</p> </div> I don't know why the order is not working and why the filter is not working. At another question, I've read about something that objects

calculate the sum of values in ng repeat Angularjs

廉价感情. 提交于 2019-11-30 07:55:36
I am new to Angularjs. I am displaying list of items using ng-repeat. how to calculate the sum of it? is there any simple method to calculate it in html using expression? name numberofyears amount interest xxx 2 4000 4% yyy 3 3000 10% zzz 5 6000 6% Total 10 13000 16% First three rows are from ng repeat.I just want to calculate the total as shown above. Thanks in advance This is pretty similar to Calculating sum of repeated elements in AngularJS ng-repeat this question. But not exactly. I am trying to calculate using expression since i have many rows It is possible to do it, but I think this

How can I get all the selected objects of Checkboxes in AngularJS?

白昼怎懂夜的黑 提交于 2019-11-30 07:38:36
I want to get all the selected objects of the checkboxes using AngularJS. Below is my code My view.tpl.html <tr ng-repeat="item in itemList"> <td> <input type="checkbox" ng-click="clickedItem(item.id)" ng-model="model.controller.object" {{item.name}} /> </td> My Controller $scope.itemList = [ { id:"1", name:"first item" }, { id:"2", title:"second item" }, { id:"3", title:"third item" } ]; $scope.selection = []; $scope.clickedItem = function(itemId) { var idx = $scope.selection.indexOf(itemId); if (idx > -1) { $scope.selection.splice(idx, 1); } // is newly selected else { var obj = selectedItem

Integration of Angular and JQuery.iCheck by using a directive is not working

末鹿安然 提交于 2019-11-30 06:53:20
I'm trying to integrate JQuery.iCheck (plugin for checkbox&Radio buttons styling). I followed few suggestions here that said that the way to integrate a jQuery plugins to be fully compatible with Angular ngRepeat is by using directives . So I implemented a directive : webApp.directive('icheck', function($timeout, $parse) { return { link: function($scope, element, $attrs) { return $timeout(function() { var ngModelGetter, value; ngModelGetter = $parse($attrs['ngModel']); value = $parse($attrs['ngValue'])($scope); return $(element).iCheck({ checkboxClass: 'icheckbox_minimal', radioClass: 'iradio

AngularJs sort object in ngRepeat

一曲冷凌霜 提交于 2019-11-30 06:48:40
I'm using AngularJs and found a problem in ordering properties of a hash object in a template. My object is like: function TestCtrl($scope){ $scope.week = {'MONDAY': ['manuel'], 'TUESDAY': [], 'WEDNESDAY': ['valerio'], 'THURSDAY': ['manuel', 'valerio'], 'FRIDAY': []} } Now, when I try to print these values in my template: <div ng-repeat="(day, names) in week"> <span>{{day}}</span> <ul> <li ng-repeat="name in names">{{name}}</li> </ul> </div> The order of the days printed is different: FRIDAY MONDAY THURSDAY TUESDAY WEDNESDAY I tried to apply the filter orderBy but I think it doesn't work with

Challenge repeating tr with ng-repeat

六月ゝ 毕业季﹏ 提交于 2019-11-30 06:47:25
I'm struggling with a special use case. I provide you with a jsfiddle snippet at the bottom. 1. The HTML table My HTML is a table. ng-repeat directive must be applied to an html element. In my use case, this cannot be done as an instance of ng-repeat is composed of a double tr element: <!-- ng-repeat the following block n times --> <tr> <td>text</td> </tr> <tr> <td tooltip="comment that is bound to the first tr">hover me</td> </tr> AngularJS doesn't provide a syntactic ng-repeat comment (unlike KnockoutJS). I found similar questions on SO. However the use case consisted of appending HTML

Angular Directive table rows issue

青春壹個敷衍的年華 提交于 2019-11-30 06:43:06
I am a beginner Angular programmer, but I am really close to understanding the directives. I create a fiddle here , but I have never used fiddle before, and it is not quite rendering ... the tr-row is a directive. I am trying to loop through the data, and print a directive (row) per record. HTML: <table ng-controller="fiddleCtrl"> <thead> <th>id</th> <th>name</th> <th>description</th> </thead> <tbody> <tr><tr-row ng-repeat="d in data" scdata="d"></tr-row></tr> </tbody> </table> javascript: var myapp = angular.module('myApp', []) .controller('fiddleCtrl', ['$scope', function ($scope) { $scope

background default image if ng-style image loaded is invalid url

不羁的心 提交于 2019-11-30 05:48:27
问题 I am adding background images to my div like this ng-style="{'background-image' : 'url('+ myvariable.for.image +')'}"> where myvariable.for.image is a url like /examplesite/image/id This works fine with one exception, if the image is not there it just doesnt do anything and my background looks too bla...If the image doesnt exist I want to be able to replace it with a default image. But I cant seem to figure out how 回答1: Instead of ngStyle I'd use a custom directive for this. Such as the

Using same controller for all CRUD operations (Rails-alike)

倖福魔咒の 提交于 2019-11-30 05:41:40
I have an angular controller that fetches a resource on creation: angular.module('adminApp') .controller('PropertiesCtrl', function ($log, $scope, Property, $location) { $scope.properties = Property.query() }); Now I want to add logic to the controller to be able to create a "Property" resource: angular.module('adminApp') .controller('PropertiesCtrl', function ($log, $scope, Property, $location) { $scope.properties = Property.query() $scope.create = function(){ //logic to create }; }); However, when I am on the form to create a "Property", an unnecessary call is made to fetch all the

Angularjs: greater than filter with ng-repeat

拈花ヽ惹草 提交于 2019-11-30 05:41:08
问题 I'm applying a greater than filter to a ng-repeat tag. I wrote the following custom filter function: $scope.priceRangeFilter = function (location) { return location.price >= $scope.minPrice; }; and I use it in the following HTML code: <div ng-repeat="m in map.markers | filter:priceRangeFilter"> What is the best way to trigger a refresh of the ng-repeat tag when $scope.minPrice is updated? 回答1: It should be automatic. When $scope.minPrice is changed, the repeater will be automatically updated.