Skip to content

Instantly share code, notes, and snippets.

@levonlee
Last active August 29, 2015 14:23
Show Gist options
  • Save levonlee/e3dffb8401ca77049b1c to your computer and use it in GitHub Desktop.
Save levonlee/e3dffb8401ca77049b1c to your computer and use it in GitHub Desktop.
Edit scope variable in ng-repeat

Edit scope variable in ng-repeat

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.js"></script>
<div ng-app="myapp" ng-controller="parentCtrl">
<div ng-repeat="x in items" ng-controller="itemCtrl">
<!-- $index is counter, start from 0 -->
{{ repeat_title + ($index+1) + ': ' + x.name + ', ' + x.citizenship }}
</div>
</div>
var app=angular.module('myapp',[]);
app.controller('parentCtrl',function($scope) {
$scope.items = [{name: 'name1', country:'Canada'}
,{name: 'name2', country:''}];
$scope.repeat_title = 'Person #';
});
app.controller('itemCtrl',function($scope) {
/* Add a variable */
$scope.x.citizenship = ($scope.x.country) ? $scope.x.country : 'N/A';
});
normalize_css: no
panel_jss: 0
panel_css: 0
wrap: b
@levonlee
Copy link
Author

resources:
- https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.js

panel_js: 0-javascript, 1-coffescript, 2-javascript 1.7
panel_css: 0-css, 1-scss
normalize_css: yes/no
wrap: l-onLoad, d-domRead, h-no wrap in head, b-no wrap in body

jsFiddle Doc: http://doc.jsfiddle.net/use/gist_read.html
Ajax response using jsFiddle: http://doc.jsfiddle.net/use/gist_response.html

URL: http://jsfiddle.net/gh/gist/{framework}/{version}/{gist_id}/

URL: http://jsfiddle.net/gh/gist/library/pure/{gist_id}/

URL: http://jsfiddle.net/gh/gist/{framework}/{version}/dependencies/{dependency_list}/{gist_id}/
http://jsfiddle.net/gh/get/mootools/1.2/dependencies/more,art/zalun/jsFiddleGithubDemo/tree/master/Demo/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment