ng-repeat

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.

Angularjs dynamic directive inside ngrepeat

℡╲_俬逩灬. 提交于 2019-11-30 05:16:29
问题 Look at example: $scope.fields = [{ name: 'Email', dir : "abc" }, { name: 'List', dir : "ddd" }]; app.directive('abc', function () {}); app.directive('ddd', function () {}); <table class="table table-hover"> <tr ng-repeat="p in fields"> <input {{p.dir}} ngmodel="p" /> </tr> </table> How can I write code, that p.dir will dynamically convert to a directive ? My example: hhttp://jsbin.com/vejib/1/edit 回答1: Try this directive: app.directive('dynamicDirective',function($compile){ return { restrict

Get old value and new value from dropdown

浪尽此生 提交于 2019-11-30 03:54:18
问题 I'm trying to simply get the previous value, and the newly selected value from a drop-down. In this example, the drop-down is pre-populated with the current group the user is assigned. When the drop-down is changed, I want to be able to return the old value and the new value. I can already get the old value, but I don't know how to return the new value. Controller Code: // User Object userAccess = [{"user_name":"dodsosr11", "group_level":1, "user_id":500, "group_id":10, "group_name":

angularjs ng-repeat ordering string arrays in numerical order

醉酒当歌 提交于 2019-11-29 23:34:13
问题 I have a list of post with ids like 1,2,3,4,5,6,7,8,9,10,11,12 (json format) The ids are of type String. But I would like to order it according to its numerical order Normal orderBy:'fiche.id' the list is displayed as below. 1,10,11,12,2,3,4,5,6,7,8,9 I would like the output to be of order - 1,2,3,4,5,6,7,8,9,10,11,12 回答1: I guess your ids are strings. A simple solution would be use a no. operation inside order by. So instead ofr orderBy:'id' just use orderBy:'id*1' this will consider the id

AngularJS - Append element to each ng-repeat iteration inside a directive

笑着哭i 提交于 2019-11-29 23:03:38
问题 I'm using a ng-repeat inside a <tr> element together with a directive. Html: <tbody> <tr ng-repeat="row in rows" create-table> <td nowrap ng-repeat="value in row | reduceString>{{value}}</td> </tr> </tbody> Directive: app.directive('createTable', function () { return { link: function (scope, element, attrs) { var contentTr = scope.$eval('"<tr ng-show="false"><td>test</td></tr>"'); $(contentTr).insertBefore(element); } } } ); Although I can append a new <tr> element to each iteration, I'm not

{{$index}} of ng-repeat computed after linker function of angular directive. $compile it?

一曲冷凌霜 提交于 2019-11-29 14:06:32
html <div repeater ng-repeat='item in items' class='first' id = '{{$index}}' > {{item}} </div> angularjs directive:- angular.module('time', []) .directive('repeater', function() { var linkFn = function(scope, element, attrs){ var id = $(element).attr('id'); alert(id); // {{$index}} } ... dynamic id created inside ng-repeat, when evoked inside directive displays as {{$index}} instead of value = 0, 1, 2 ... How do you ensure when Linker function in directive executes the dynamic ids are used? I think it can be done using $compile inside the directive. But i can't quite figure how? $compile

ng-repeat orderBy object

此生再无相见时 提交于 2019-11-29 10:25:23
UPDATE: on my html page I'm using as the following: <section ng-repeat="template in templates"> <ng-include src="template"></ng-include> </section> but the problem is that I need specific file in certain order so is there a way I can control the way order is rendering? I'm trying to orderby an object how do I do that and I have searched online before posting it here. function MyCtrl($scope) { $scope.templates = { template_address: "../template/address.html", template_book: "../template/book.html", template_create: "../template/create.html" }; <div ng-app ng-controller="MyCtrl"> <ul> <li ng

Dygraphs not working with ng-repeat

大城市里の小女人 提交于 2019-11-29 05:20:15
I'm new to AngularJS and building a dashboard with dygraphs . Tried to put the example code from the dygraphs website in an ng-repeat-list, just to test. Expected the same sample graph for every x in y. Unfortunately the graph doesn't get drawn, just the axes, console doesn't show any errors. <li ng-repeat="x in y"> <div id="graph"> <script> new Dygraph(document.getElementById("graph"), [ [1,10,100], [2,20,80], [3,50,60], [4,70,80] ], { labels: [ "x", "A", "B" ] }); </script> </div> </li> If I remove ng-repeat, it works though (single graph) – so the dygraphs-code is valid. Of course it doesn

Angular directive with ng-repeat, ng-show “Show more” and lazy-load

我怕爱的太早我们不能终老 提交于 2019-11-28 23:39:28
I use this directive, iterating over an array "myArr", filtering for a few conditions. <myDirective myData='item' ng-repeat="item in filteredArr = (myArr | filter:searchField | filter:checkboxFilter)" ng-show="$index < visible" /> This gives me two issues I'd like to get some input on: a) the ng-show part is there because I have a condition that handles this: <p> <a ng-click='visible=visible+10' ng-show='visible < filteredArr.length'>Show more</a> </p> in order to show or hide the "Show more" part. I cannot come up with another idea on toggling this and/or the items itself. $scope.visible is,

Assigning ng-model to checkboxes generated by ng-repeat

两盒软妹~` 提交于 2019-11-28 23:33:53
I have set up a json containing a list of countries with an ID and Country code attached: It looks like this: $scope.countries = [ {"name":"Afghanistan","id":"AFG","country-code":"004"}, {"name":"Åland Islands","id":"ALA","country-code":"248"}, {"name":"Albania","id":"ALB","country-code":"008"}, {"name":"Algeria","id":"DZA","country-code":"012"} ] I then use the ng-repeat directive to create checkbox inputs for every country. <div ng-repeat="country in countries"> <label><input type="checkbox" ng-model="{{country.id}}" ng-true-value="'{{country.name}}'" ng-false-value="''">{{country.name}}<