angularjs-ng-repeat

Angular passing scope to ng-include

大憨熊 提交于 2019-11-27 19:37:35
I have a controller that I wrote that I use in multiple places in my app with ng-include and ng-repeat , like this: <div ng-repeat="item in items" ng-include="'item.html'" ng-controller="ItemController" ></div> In the controller/template, I expect the item value to exist, and the whole thing is built around this idea. Now, though, I need to use the controller in a slightly different way, without the ng-repeat , but still need to be able to pass in an item . I saw ng-init and thought it could do what I needed, like this: <div ng-init="item = leftItem" ng-include="'item.html'" ng-controller=

Angular ng-repeat with ng-form, accessing validation in controller

大憨熊 提交于 2019-11-27 19:19:12
I am trying to generate an editable list using ng-repeat . I want to remind the user to update any edits before moving on, so I am using ng-form to create "nested" forms on the fly because the documentation says I can then use validation on these dynamically created inputs. While that seems to work within the HTML, I don't see how to access those dynamically created forms and related validation fields in the controller. Specifically, when the user changes the input I use the form $dirty property to bring up a button to tell the user to commit the changes. So far, so good. However, once the

Angular.js ng-switch-when not working with dynamic data?

北战南征 提交于 2019-11-27 19:02:16
I'm trying to get Angular to generate a CSS slider based on my data. I know that the data is there and am able to generate it for the buttons, but the code won't populate the ng-switch-when for some reason. When I inspect the code, I see this twice (which I know to be correct as I only have two items): <div ng-repeat="assignment in assignments" ng-animate="'animate'" class="ng-scope"> <!-- ngSwitchWhen: {{assignment.id}} --> </div> My actual code: <div ng-init="thisAssignment='one'"> <div class="btn-group assignments" style="display: block; text-align: center; margin-bottom: 10px"> <span ng

Using ng-repeat on JSON containing JSON

坚强是说给别人听的谎言 提交于 2019-11-27 18:49:22
I'm somewhat new to angular, and i'm having problems with my json and ng-repeats. I have a list of "modules" and then lists of "weeks" within them: { "modules": { "module1": { "title":"name of module1", "description":"description of module1", "weeks":{"week1":{"title":"Week 01"} }, "module2": { "title":"name of module2", "description":"description of module2", "weeks":{"week2":{"title":"Week 02"},"week3":{"title":"Week 03"} } } } my final output is a table, and I can get the modules to repeat, but I'm having a hard time understanding what I'm doing wrong by getting the weeks to loop. Here is

How to retain scroll position of ng-repeat in AngularJS?

若如初见. 提交于 2019-11-27 18:46:06
DEMO List of objects is rendered using ng-repeat . Suppose that this list is very long and user is scrolling to the bottom to see some objects. While user is observing an object, a new item is added to the top of the list. This causes the observed object to change its position, i.e. the user suddenly sees something else at the same place of the observed object. How would you go about keeping the observed object at the same place when new items are added? PLAYGROUND HERE It maybe solved quite elegantly, by using scrollTop property of div . I used two directives - one handles scroll position of

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

天大地大妈咪最大 提交于 2019-11-27 18:40:42
问题 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. 回答1: 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=

Progressive loading in ng-repeat for images, angular js

可紊 提交于 2019-11-27 18:24:08
How do I implement progressive loading of content as you scroll down the page? Otherwise 1000 images would load at the same time. EpokK Use infinite scrolling directive. ngInfiniteScroll DEMO HTML <div ng-app='myApp' ng-controller='DemoController'> <div infinite-scroll='loadMore()' infinite-scroll-distance='2'> <img ng-repeat='image in images' ng-src='http://placehold.it/225x250&text={{image}}'> </div> </div> JS var myApp = angular.module('myApp', ['infinite-scroll']); myApp.controller('DemoController', function($scope) { $scope.images = [1, 2, 3, 4, 5, 6, 7, 8]; $scope.loadMore = function() {

How does ng-repeat work?

社会主义新天地 提交于 2019-11-27 18:14:47
问题 I dissected ng-repeat and extracted the code blocks attached, seeing that these comprise the logic that handles the repeating algorithm (which I want to understand how it works). I have quite a few questions, but since they are all about the internals of ng-repeat I chose to ask them all here. I don't see any reason to separate them into different SO questions. I have marked inline to which line(s) of code each question refers to. Why do they need to make sure that trackById is not the native

configure angularjs module to send patch request

寵の児 提交于 2019-11-27 18:09:35
问题 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

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

耗尽温柔 提交于 2019-11-27 17:48:56
问题 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>