zoukankan      html  css  js  c++  java
  • 【转】AngularJS动态生成div的ID

    AngularJS动态生成div的ID

    原文链接:http://blog.csdn.net/you23hai45/article/details/52348078

    1、问题背景

         给定一个数组对象,里面是div的id;循环生成div元素,并给id赋值

    2、实现源码

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title>AngularJS动态生成div的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.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>
            </div>
        </body>
    </html>

     

    3、实现结果

    <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动态生成div的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.divIds = [
                        {divId:"chartId1"},
                        {divId:"chartId2"},
                        {divId:"chartId3"},
                        {divId:"chartId4"},
                        {divId:"chartId5"}
                    ];
                });
            </script>
        </head>
        <body ng-controller="idCon" ng-app="idApp" class="ng-scope">
            <!-- ngRepeat: chart in divIds --><div ng-repeat="chart in divIds" class="ng-scope">
                <div id="chartId1" class="ng-binding">chartId1</div>
            </div><!-- end ngRepeat: chart in divIds --><div ng-repeat="chart in divIds" class="ng-scope">
                <div id="chartId2" class="ng-binding">chartId2</div>
            </div><!-- end ngRepeat: chart in divIds --><div ng-repeat="chart in divIds" class="ng-scope">
                <div id="chartId3" class="ng-binding">chartId3</div>
            </div><!-- end ngRepeat: chart in divIds --><div ng-repeat="chart in divIds" class="ng-scope">
                <div id="chartId4" class="ng-binding">chartId4</div>
            </div><!-- end ngRepeat: chart in divIds --><div ng-repeat="chart in divIds" class="ng-scope">
                <div id="chartId5" class="ng-binding">chartId5</div>
            </div><!-- end ngRepeat: chart in divIds -->
        
    
    </body></html>
     


     
  • 相关阅读:
    PAT查找题---1032 挖掘机技术哪家强 (20分)
    PAT查找题---1028 人口普查 (20分)
    PAT查找题---1004 成绩排名 (20分)
    01_1JAVA简介
    01考试简介
    shell时间变量拼接问题
    如何将oracle查询的结果传输给变量
    生产环境邮件问题总结
    mutt+msmtp做linux邮件客户端
    linux配置邮件客户端
  • 原文地址:https://www.cnblogs.com/wdtzms/p/6557792.html
Copyright © 2011-2022 走看看