1、問題背景
給定一個陣列對象,裡面是p的id;循環產生p元素,並給id賦值
2、實現源碼實現結果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>AngularJS动态生成p的ID</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.pIds = [ {pId:"chartId1"}, {pId:"chartId2"}, {pId:"chartId3"}, {pId:"chartId4"}, {pId:"chartId5"} ]; }); </script> </head> <body ng-app="idApp" ng-controller="idCon"> <p ng-repeat="chart in pIds"> <p id="{{chart.pId}}">{{chart.pId}}</p> </p> </body> </html>
以上就是AngularJS動態產生p的ID的內容,更多相關內容請關注PHP中文網(www.php.cn)! 相關文章:
AngularJS實作動態編譯加入dom的方法
AngularJs 動態載入模組與相依