Use of ng -if and angularjs

0

It turns out that I have this switch generated dynamically with ng-repeat :

       <div ng-repeat="model in modelo_final">
         <div style="float:left; padding-right:100px;">
         <div class="can-toggle demo-rebrand-2">
         <input  id={{model.id}} type="checkbox" ng-model="idrecibo[model.id]" ng-change="changeItem(model.id)">
          <label for={{model.id}}>
           <div class="can-toggle__switch" data-checked="{{identificador2}}" data-unchecked="{{identificador}}"></div>
           <div class="can-toggle__label-text"><p style="font-size:15px; width:100px;">{{model.nombre}}</p></div>
           </label>
           </div>
         </div>
       </div>

and within all the operation that it fulfills, I just need to configure so that when I open the page it shows activated those that are active !, that is, it does not always return to false when reloading the page.

To know that, model brings together id and name an active which is 0 is deactivated, 1 activated.

then I thought about creating a ng-if and asking if it is 1 that activates the switches but I can not find the class that activates the switch, so investigate seems to activate: ng-not-empty and deactivates ng-empty

the switch link is this . According to you how should I do ng-if ?

    
asked by Hernan Humaña 21.12.2016 в 13:56
source

1 answer

1

Your switch has the ng-model="idrecibo[model.id]" therefore it is that value that must come true or false depending on whether it is active or not.

Remember that according to my answer in a question you passed, to create dynamic models you created a modelo_final arrangement, when you think it does the following

angular.forEach($scope.modelo_final, function(modulo, index){
   if(modulo.activo == 1){
      $scope.idrecibo[modulo.id] = true;
   }else{
      $scope.idrecibo[modulo.id] = false;
   }
})
    
answered by 21.12.2016 / 14:11
source