user310291
user310291

Reputation: 38180

why my ng-repeat doesn't work

I try to do this https://jsfiddle.net/u6qdfw5f/1/ using angularjs but it stays blank https://jsfiddle.net/cs3rpy83/5/ I can't see why.

          <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>

Upvotes: 0

Views: 92

Answers (1)

eran otzap
eran otzap

Reputation: 12533

You have to init sections before calling 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>

Upvotes: 2

Related Questions