Use ng-attr-your-attribute
to conditionally add or remove an attribute in HTML element.
AngularJS 1.3 above
Last active
August 29, 2015 14:23
-
-
Save levonlee/c2c18577453b26462e1f to your computer and use it in GitHub Desktop.
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-attr-data-id="{{x.id || undefined}}"> | |
<!-- Another way --> | |
<div ng-attr-data-id="{{ (show) ? x.id : undefined }}"> | |
{{ repeat_title + ($index+1) + ': ' + x.name }} | |
</div> | |
</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', id:1} | |
,{name: 'name2', id:2}]; | |
$scope.repeat_title = 'Person #'; | |
$scope.show = 1; | |
}); |
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