angularjs-ng-repeat

AngularJS: code not working when iterating through object [duplicate]

冷暖自知 提交于 2019-11-29 17:15:28
This question already has an answer here: 'this' vs $scope in AngularJS controllers 7 answers I am trying to populate a list of employee objects from my controller empctrl in a template. Here's the controller: app.controller('employeeController', function ($scope, employeeService) { this.employees = {}; this.populateTable = function (data) { this.employees = data; }; var error = function (err) { console.log("Error: " + err); }; // Call Service to List all Employees console.log("Service called to populate table."); employeeService.output().then(this.populateTable, error); this.populateTable();

How to properly execute a function inside ng-repeat

对着背影说爱祢 提交于 2019-11-29 16:59:14
问题 SITUATION: I am making an app in AngularJs that assign permissions. In order to do this i have three nested ng-repeat. First loop : display PERMISSION GROUP Second loop : For each permission group display CATEGORIES. Inside this loop execute a function that will get all the SUB CATEGORIES for each category Third loop : display SUB CATEGORIES ISSUE: The problem is in the execution of the function inside the second loop. ATTEMPT 1 - ng-init: <div class="row" ng-repeat="permission_group in list

angularjs: ng-repeat-start and ng-repeat-end with inner ng-repeat

筅森魡賤 提交于 2019-11-29 16:55:19
问题 Hi I have a simple use case for ng-repeat-start and end and is working just fine, the problem appears when I want to add an inner ng-repeat. Here is the my code <tr ng-repeat-start="obj in rows" > <td ng-repeat="e in obj.row">{{e}}</td> </tr> <tr ng-repeat-end> <td colspan="4">{{obj.description}}</td> <tr> The inner ng-repeat into td element is not working, I'm seeing the ngRepeat comment when I inspect the html source code, but the td elements are not being created. <!-- ngRepeat: e in obj

{{$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

OrderBy boolean value with AngularJS ng-repeat

天大地大妈咪最大 提交于 2019-11-29 13:40:15
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 do this: <div ng-repeat="group in groups | filter:{value:true}"> {{group.name}} {{group.value}} </div>

How do I generate nested table in one column if it has list of values using angular js?

非 Y 不嫁゛ 提交于 2019-11-29 12:42:27
index.js var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope) { $scope.name = 'World'; $scope.data =[{"Id":1,"Title":"en-US","Description":"UnitedStates","MyValues":[{"Id":100,"Value":"Save"}]}, {"Id":1,"Title":"en-UK","Description":"UK","MyValues":[{"Id":102,"Value":"Delete"}]}] $scope.cols = Object.keys($scope.data[0]); $scope.notSorted = function(obj){ if (!obj) { return []; } return Object.keys(obj); } }); index.html <table border=1> <thead> <tr> <th ng-repeat="key in notSorted(cols)" ng-init="value=cols[key]">{{value}}</th> </tr> </thead> <tbody> <tr ng

Angularjs templateUrl fails to bind attributes inside ng-repeat

假装没事ソ 提交于 2019-11-29 12:23:31
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: { snippet: '@'}, templateUrl: function(elem, attrs) { console.log('We try to load the following

Angularjs dynamically adding and removing elements using directive

感情迁移 提交于 2019-11-29 12:19:33
I used directive for creating contact form. Initially i create customerForm directive for displaying customer form. In that form i have one button, when we click on add button, called getData function and that function internally used newDirective for displaying ul list. for that i used $compile api for compiling html code. that is fine and its also display list value and remove button when we click on remove button, its called scope.remove() function. But its delete only ones. after that i cant remove any element (i.e. button). i dont know why its happening. please help me. jsfiddle index

ng-repeat is not updating when array is changed

谁说我不能喝 提交于 2019-11-29 11:56:23
I have an ng-repeat that isn't updating upon changing the data in the array that it is using. I've researched for quite a while but nothing seems to be working. Initially, when the page loads, the ng-repeat displays the first page of a dataset, upon getting new data (the next page) and setting that array with this data, the ng-repeat isn't noticing the change and never populates with the updated array. It would be greatly appreciated if someone could steer me in the right direction on this. gatekeeper.controller('businessController', ['$scope', 'siteService', function($scope, siteService) {

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

≯℡__Kan透↙ 提交于 2019-11-29 10:57:52
问题 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