1. Problem background
Given an array object, the id of the div; loop to generate the div element and assign the id value
2. Implement source code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>AngularJS dynamically generates the ID of the div</title> <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> <script> var app = angular.module("idApp",[]); app.controller("idCon",function($scope){ $scope.divIds = [ {divId:"chartId1"}, {divId:"chartId2"}, {divId:"chartId3"}, {divId:"chartId4"}, {divId:"chartId5"} ]; }); </script> </head> <body ng-app="idApp" ng-controller="idCon"> <div ng-repeat="chart in divIds"> <div id="{{chart.divId}}">{{chart.divId}}</div> </body> </html>3. Achieve results
<html><head><style type="text/css">@charset "UTF-8";[ng/:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide:not(.ng-hide-animate){display:none !important;}ng/:form{display:block;}.ng-animate-shim{visibility:hidden;}.ng-anchor{position:absolute;}</style> <meta charset="UTF-8"> <title>angularJS dynamically generates the ID of the div</title> <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> <script> var app = angular.module("idApp",[]); app.controller("idCon",function($scope){ $scope.divIds = [ {divId:"chartId1"}, {divId:"chartId2"}, {divId:"chartId3"}, {divId:"chartId4"}, {divId:"chartId5"} ]; }); </script> </head> <body ng-controller="idCon" ng-app="idApp"> <!-- ngRepeat: chart in divIds --><div ng-repeat="chart in divIds"> <div id="chartId1">chartId1</div> </div><!-- end ngRepeat: chart in divIds --><div ng-repeat="chart in divIds"> <div id="chartId3">chartId3</div> </div><!-- end ngRepeat: chart in divIds --><div ng-repeat="chart in divIds"> <div id="chartId3">chartId3</div> </div><!-- end ngRepeat: chart in divIds --><div ng-repeat="chart in divIds"> <div id="chartId4">chartId4</div> </div><!-- end ngRepeat: chart in divIds --><div ng-repeat="chart in divIds"> <div id="chartId5">chartId5</div> </div><!-- end ngRepeat: chart in divIds --> </body></html>The above is the ID source code analysis of AngularJS dynamically generated div introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!