javascript - 为什么我的 ng-repeat 不起作用

标签 javascript angularjs

我尝试这样做https://jsfiddle.net/u6qdfw5f/1/使用 angularjs 但它保持空白 https://jsfiddle.net/cs3rpy83/5/我不明白为什么。

          <title>The W3.CSS Example</title>
  <body ng-app ng-init="app='accordion'">
<div class="w3-accordion w3-light-grey">
<div ng-repeat= "section in sections" ng-init="sections=['section 1','section 2']">
  <button onclick="myFunction('Demo1')" class="w3-btn-block w3-left-align">
    Open Section 1
  </button>
  <div id="Demo1" class="w3-accordion-content w3-container">
    <p>Some text..</p>
  </div>

  </div>


</div>

   </body>

最佳答案

您必须在调用 ng-repeat 之前初始化部分

 <div ng-init="sections=['section 1','section 2']">
     <div ng-repeat= "section in sections">
           <button onclick="myFunction('Demo1')" class="w3-btn-block w3-left-align">
              Open Section 1
           </button>
        <div id="Demo1" class="w3-accordion-content w3-container">
            <p>Some text..</p>
       </div>
  </div>

关于javascript - 为什么我的 ng-repeat 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41532859/

相关文章:

javascript - 选项值数据绑定(bind)不起作用

javascript - Ckeditor - 为什么 dataProcessor.htmlFilter.addRules 不起作用?如何修复它?

angularjs - 从图库中选择图像时进行 ionic 图像裁剪

javascript - ng-grid是否支持按行进行单元格过滤( Angular 过滤)

javascript - 重置表单字段时出错

Javascript PHP/MySQL - 将数据库中的行值插入文本字段

javascript - 与 .click(function() {...}) 绑定(bind)的对象;对点击没有影响

javascript - 如何防止路径再次被填满?

angularjs - CRUD在angularJs和struts2中的应用

javascript - 使用 AngularJS 选择多个显示名称而不是 ID