title: Dynamic ng-init - Angularjs
body: <p>I got this:</p>
  
  <pre><code>&lt;ul id="filterList"&gt;
        &lt;div ng-repeat="data in dataForTheTree"&gt;
           &lt;li&gt; {{data.topic}} &lt;/li&gt;
            &lt;ul id={{data.topic}}Son&gt;
                &lt;li ng-repeat="d in data.children&gt;  
                   &lt;input type="checkbox" ng-init='{{d.subtopic}}Checkbox = true' ng-checked = "{{d.subtopic}}Checkbox"/&gt;{{d.subtopic}}
                &lt;/li&gt;
            &lt;/ul&gt;
        &lt;/div&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I need to create a "model" to know if the checkbox is checked or not (i can not use ng-model because is a bad practice). So, I am trying with ng-checked.
  ng-checked will not work if i can not initialise it. I want to try with ng-init because is the only thing that i have read about it.</p>
  
  <p>I have read something about ng-init in a similar post, but i can not understand because I am so new in this world.</p>
  
  <p>"You need to access dynamic properties using [] notation instead on . notation"</p>
  
  <p>How can i do that in this example?</p>
  
  <p>This is my .Json:</p>
  
  <pre><code>$scope.dataForTheTree =[
    { "topic" : "Legislation", "children" : [
        { "subtopic" : "Education", "texto" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae tincidunt mi. Donec purus ligula, tincidunt ut semper eu, laoreet.", "children" : [] },
        { "subtopic" : "HealthService", "texto" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae tincidunt mi. Donec purus ligula, tincidunt ut semper eu, laoreet.", "children" : [] },
        { "subtopic" : "Assets", "texto" : " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae tincidunt mi. Donec purus ligula, tincidunt ut semper eu, laoreet.", "children" : [] },
        { "subtopic" : "LiquidAssets", "texto" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae tincidunt mi. Donec purus ligula, tincidunt ut semper eu, laoreet.", "children" : [] },
        { "subtopic" : "Education", "texto" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae tincidunt mi. Donec purus ligula, tincidunt ut semper eu, laoreet.", "children" : [] },
        { "subtopic" : "HealthService", "texto" : " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae tincidunt mi. Donec purus ligula, tincidunt ut semper eu, laoreet.", "children" : [] },
        { "subtopic" : "HealthService", "texto" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae tincidunt mi. Donec purus ligula, tincidunt ut semper eu, laoreet.", "children" : [] }
  ]}];
  </code></pre>
  
  <p>I want to link each checkbox with his subtopic, then I want to watch if the checkbox is checked through <code>ng-checked = "{{d.subtopic}}Checkbox"</code>.</p>
  
  <p>Now my problem is that <code>"{{d.subtopic}}Checkbox"</code> is not initialised, and that is why I need to use ng-init.</p>
  
  <p>The problem here is that ng-init does not understand {{}}, so I do not know how to solve this: <code>'{{d.subtopic}}Checkbox = true'</code></p>
  
  <p>Finally I just want to get a dynamic $scope, like for example:</p>
  
  <pre><code>var cad = subtopic+"Checkbox";
  
    if($scope[cad] === true){ [...]
  </code></pre>