ng-repeat

How to remove object from array within ng-repeat with AngularJS?

十年热恋 提交于 2021-02-08 05:48:47
问题 I am having an array with objects like [{...}, {...}] which I am outputting with ng-repeat. Then I have a delete button with a function to delete it. Is there a simple way to delete it in AngularJS, perhaps with $index? Or I need to specify an ID on every object as an property? 回答1: If you don't apply a filter to reorder or filter your array, you can do this: <div ng-repeat="item in items" ng-click="delete($index)">{{item}}</div> And the delete function: $scope.items = [...]; $scope.delete =

Prevent multiple select to have the same value

北城以北 提交于 2020-12-13 04:24:06
问题 What it should do I want to prevent the user to be able to select twice the same option in multiple <select> having the same options. What it is doing When selecting a value on the first dropdown, the second won't have the option visible (great). But when selecting a value on the second dropdown (and the first one already have one), it's deleting all the selections. I end up with a selection [null, null] . Am I missing something? JSFiddle var app = angular.module('App', []); app.controller(

Prevent multiple select to have the same value

眉间皱痕 提交于 2020-12-13 04:24:05
问题 What it should do I want to prevent the user to be able to select twice the same option in multiple <select> having the same options. What it is doing When selecting a value on the first dropdown, the second won't have the option visible (great). But when selecting a value on the second dropdown (and the first one already have one), it's deleting all the selections. I end up with a selection [null, null] . Am I missing something? JSFiddle var app = angular.module('App', []); app.controller(

Filter on ng-repeat with ng-model value

江枫思渺然 提交于 2020-02-29 04:25:23
问题 I need to filter ng-repeat on value of ng-model Like this : <select class="browser-default" ng-model="planning.uuid" id="planning" ng-options="planning.uuid as planning.day for planning in plannings" ng-change="loadRegistration(planning.uuid)"> <option value="" disabled selected>Planning</option> </select> ... <table... <tr ng-repeat="registration in registrations" > <td ng-repeat="rate in registration.rate | filter: rate.activity.uuid: planning.activity.uuid"> {{rate.type.label}} </td> </tr>

ng-options用法详解

北城以北 提交于 2020-02-17 14:45:50
原文地址: http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/ng-options-usage/ ng-options属性可以在表达式中使用数组或对象来自动生成一个select中的option列表。ng-options与ng-repeat很相似,很多时候可以用ng-repeat来代替ng-options。但是ng-options提供了一些好处,例如减少内存提高速度,以及提供选择框的选项来让用户选择。当select中一个选项被选择,该选项将会被绑定到ng-model。如果你想设一个默认值,可以像这样: $scope.selected = $scope.collection[ 3 ] 。 之前一直在用ng-repeat就见到过track by,没有去了解它的用法,这次了解了一下。track by主要是防止值有重复,angularjs会报错。因为angularjs需要一个唯一值来与生成的dom绑定,以方便追踪数据。 例如:items=[“a”,“a”,“b”],这样ng-repeat=“item in items”就会出错,而用ng-repeat=“ (key,value) in items track by key ”就不会出现错误了。 ng-options一般有以下用法: 对于数组: label for value

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

♀尐吖头ヾ 提交于 2020-01-28 10:41:05
问题 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

AngularJS two-way data binding not working properly in directive

纵饮孤独 提交于 2020-01-24 00:29:08
问题 i am trying to implement radio-button list using ng-repeat. typeList.html <div ng-repeat="type in types" > <input type="radio" id={{type.id}} name="{{type.name}}" ng-model="result" ng-value="type.id" > {{type.name}} <div> Result {{result}} </div> //result is changing only in the row of clicked radio-button. It should change in every row.(two way data-binding). </div> Directive: angular.module('app').directive('myList',function(){ return{ restrict: 'A', scope: { types: '=', //here list is

AngularJS ng-repeat is not showing table data

て烟熏妆下的殇ゞ 提交于 2020-01-17 14:35:21
问题 my controller bring data from spring app data but it does not get displayed in form. When I put constants in data it works perfectly fine. here is my code in JS controller sampleApp.controller('searchCourseController', ['$scope', '$http', function($scope, $http, $routeParams, ngTableParams ) { $scope.courses = {}; $scope.searchButton=function () { var actionUrl = 'searchCourse'; var textToSearch = $("#txtTitle").val(); if (textToSearch.length == 0) { alert("Please provide search criteria.

How to repeat “key” in ngRepeat one time only (AngularJS)

懵懂的女人 提交于 2020-01-17 04:55:06
问题 The problem is leaving in the JSON Array response from the Backend/DB. I'm getting the response of the database in the correct json format: [ 0: { "Grade": 100, "AB001": 1, "AB002": 0, "AB003": 9, "AB004": 5 }, 1: { "Grade": 98, "AB001": 3, "AB002": 0, "AB003": 0, "AB004": 0 } ... ] (10 objects as result) Thus displayed in the Firebug console, when you click the Response of the GET Request. To retrieve the keys who are represented in double quotes I've used the ngRepeat directive in my view

Select input shown with ng-show

跟風遠走 提交于 2020-01-16 19:14:46
问题 I'd like to put the focus on an input after it's shown with ng-show. However, this requires a jquery call to be made after the $digest cycle. Does anyone know how to run code after the item is shown, without resorting to setTimeout(), or some such thing? Here's an example plunk of the issue: http://plnkr.co/edit/synSIP?p=preview 回答1: You can write a simple directive , dont need jquery : yourApp.directive('focusme',function(){ return function(scope,elem,att){ elem.focus(); } }); and You can