Edit scope variable in ng-repeat
Last active
August 29, 2015 14:23
-
-
Save levonlee/e3dffb8401ca77049b1c to your computer and use it in GitHub Desktop.
Edit scope variable in ng-repeat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
normalize_css: no | |
panel_jss: 0 | |
panel_css: 0 | |
wrap: b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/