angularjs-ng-repeat

AngularJS - Set default value on select inside a ng-repeat [duplicate]

戏子无情 提交于 2019-11-29 06:10:47
This question already has an answer here: AngularJS. When select have ng-model attribute, ng-selected not working 2 answers I'm facing to an issue with AngularJS - I'm not able to display the selected value in a <select> . Here is my use case: I have a view which starts by an ng-repeat to display components. Each component contains a select to choose the vat rate. When creating new items, it looks fine. But when I'm editing existing items, the actual vatRate code is not displayed in the select, and instead I see the default option "-- Select VAT Rate --" instead of the selected VAT. My model

AngularJS: find the index position of filtered value in the original array

只愿长相守 提交于 2019-11-29 06:07:17
问题 $scope.data = [ { "name": "Jim", "id" : 25 }, { "name": "Jerry", "id": 27 }, { "name": "Rithika", "id": 20 } ]; <div ng-repeat="person in data | filter: {id:20}"> {{parent_index}} </div> parent_index - Index of the filtered element in the actual array. In this example, parent_index should return 2. how to find it? 回答1: find the index position of filtered value in the original array Try this one: <div ng-repeat="person in data | filter: {id:20}"> {{data.indexOf(person)}} </div> Output: 2 Demo

Angular list with ng-repeat with date as divider

大城市里の小女人 提交于 2019-11-29 05:19:58
I've got a JSON object with different events that looks like this: { "error":false, "events":[ { "id":1, "title":"First entry", "date":"2014-11-04" }, { "id":2, "title":"Second entry", "date":"2014-11-04" }, { "id":3, "title":"Third entry", "date":"2014-11-05" }, { "id":4, "title":"Fourth entry", "date":"2014-11-06" }, { "id":5, "title":"Fifth entry", "date":"2014-11-06" } ] } This object is stored in $scope.events in my controller. Now I'm looping this array to build the list of events: <ion-list> <div class="item item-divider"> {{event.date}} </div> <a class="item item-thumbnail-left" href="

AngularJS filtering between a range

折月煮酒 提交于 2019-11-29 04:39:24
I have set up a range slider that ranges from 0 - 2hr, the times are calculated in mins then converted to hh:mm like this: 10min, 20min, 1hr 20min, 2hr. But now I am trying to filter a bunch of items inside the ng-repeat using the range specified by the range slider and I am having a hard time getting this working. Here is what I have done http://cdpn.io/LDusa I am using http://danielcrisp.github.io/angular-rangeslider/demo/ for the range slider. And here is the code: var app = angular.module('myApp', ['ui-rangeSlider']); app.controller('myCtrl', function ($scope) { $scope.sliderConfig = { min

AngularJS InfDig error (infinite loop) with ng-repeat function that returns array of objects

末鹿安然 提交于 2019-11-29 04:28:10
Here's my code: <h1 ng-repeat="item in func()">something</h1> $scope.func = function(){ return [{"property" : "value1"},{"property": "value2"}]; } In Angular.js v. 1.1.1 there's no mistake. In Angular.JS v 1.2.1 I get an infDig mistake. Fiddle of v.1.1.1 Fiddle of v.1.2.1 Could you explain this situation? Thanks a lot. m59 As of AngularJS 1.2: The "track by" expression was added to ng-repeat and more appropriately addresses this issue as demonstrated in the following code. <h1 ng-repeat="item in func() track by $index">something</h1> $scope.func = function(){ return [{"property" : "value1"},{

Applying ng-class based on value

China☆狼群 提交于 2019-11-29 03:54:05
I have a simple ng-repeat that displays a list of scores and a value of either Positive or Negative. What i am trying to do is when the value is Negative, display a red background CSS class, and when Positive, display a green CSS class. However, for some reason, i am always seeing the red CSS class on my page. HTML: <tr ng-repeat="scores in Test" ng-class="{true: 'warning', false: 'ok'}[scores.Indicator == 'Negative']"> <td>Overall: {{ scores.Indicator }}</td> </tr> CSS: .warning { background: red; } .ok { background: green; } I haven't seen that particular syntax used before, what's the

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

大兔子大兔子 提交于 2019-11-29 03:54:04
问题 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 }; });

configure angularjs module to send patch request

微笑、不失礼 提交于 2019-11-29 03:53:54
I am totally new to AngularJs. I am trying to send a PATCH request using Angularjs to Django Tastypie API's. My code is var module = angular.module('myApp', []); module.config(function ($httpProvider) { }); function MyController($scope,$http) { $scope.patchCall=function(){ $http({ url: "/patchrequest/", data:data, method: "PATCH", }) .success(function(data){ console.log("SUCCESS"); $scope.list = data.items; }).error(function() { console.log("FAIL"); }); } } But when I am trying to send a request using this code I am Getting an error that http.patch is not a function. Tell me how can i

Angular.js view doesn't update when nested $scope array is updated

笑着哭i 提交于 2019-11-29 03:50:43
I am trying to make an angular.js view update itself when adding a comment. My code is as follows: <div class="comment clearfix" data-ng-repeat="comment in currentItem.comments" data-ng-class="{bubble: $first}" data-ng-instant> <div> <p> <span class="username">{{comment.user}}</span> {{comment.message}} </p> <p class="time"> 10 minutes ago </p> </div> </div> <div class="comment reply"> <div class="row-fluid"> <div class="span1"> <img src="assets/img/samples/user2.jpg" alt="user2" /> </div> <div class="span11"> <textarea class="input-block-level addComment" type="text" placeholder="Reply…"><

Using Modal Window inside ng-repeat

旧城冷巷雨未停 提交于 2019-11-29 03:48:20
问题 I have a ng-repeat and I am trying to add a modal that passes the same scope variable to the modal window. I am able to get the modal window to open but the scope value from ng-repeat is not showing inside the modal. Hopefully my code explains better. This is what I have so far: <div ng-controller="CustomerController"> <div ng-repeat="customer in customers"> <button class="btn btn-default" ng-click="open()">{{ customer.name }}</button> <!--MODAL WINDOW--> <script type="text/ng-template" id=