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

时间:2017-01-08 12:48:39

标签: javascript angularjs

我尝试使用angularjs执行此操作https://jsfiddle.net/u6qdfw5f/1/但它保持空白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>

1 个答案:

答案 0 :(得分:2)

在调用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>