1. Problemhintergrund
Bei einem Array -Objekt die ID der Div; Schleife zum Generieren des DIV -Elements und dem ID -Wert zuweisen
2. Implementieren Sie den Quellcode
<! DocType html> <html> <head> <meta charset = "utf-8"> <tits> AngularJs generiert dynamisch die ID des Div </title> <script src = "http://apps.bdimg.com/libs/angular.js/1.6/angular Angular.module ("idapp", []); app.Controller ("idcon", function ($ scope) {$ scope.divids = [{divid: "chartId1"}, {divid: "chartid2"}, {divid: "chartid3"}, {divid: "chartid4"}, {divid: chartid3 "}];}); </script> </head> <body ng-app = "idapp" ng-controller = "idcon"> <div ng-repeat = "chart in divids"> <div id = "{{{{{{divid}}}"> {{{Diagramm}} </div> </body> </html>>3.. Ergebnisse erzielen
<html> <pead> <style type = "text/css">@charset "utf-8"; [ng/: cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], ng-cloak, .x-ng-cloak, .ng-hide: nicht (.nghide) ! 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: chartid3 "}];}); </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> <!-Ende nGrepeat: chart in divids-> <div ng-repeat = "chart in divids"> <divid = "chartid3"> chartid3 </div> </div> <!-Ende nGrepeat: chart in divids-> <divids-repeat = "chart in divids" 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>Das obige ist die ID -Quellcodeanalyse von AngularJs, die Ihnen dynamisch erzeugte DIV eingeführt haben. Ich hoffe, es wird Ihnen hilfreich sein. Wenn Sie Fragen haben, hinterlassen Sie mir bitte eine Nachricht und der Editor wird Ihnen rechtzeitig antworten. Vielen Dank für Ihre Unterstützung auf der Wulin.com -Website!