Ich habe eine Liste von Kontrollkästchen, wie folgend:Wie eine Liste von Kontrollkästchen in AngularJS binden
formationSelection = [
{
codeFormation: 1,
nom: "ENSA"
},
{
codeFormation: 2,
nom: "CPGE"
}
]
In einem anderen Szenario:
<div flex="50" ng-repeat="formationType in formationTypeList">
<md-checkbox class="md-warn md-align-top-left"
value="{{formationType.codeFormation}}"
name="formationSelection[]"
ng-checked="formationSelection.indexOf(formationType) > -1"
ng-click="toggleFormationTypeSelection(formationType)">
{{ formationType.nom }}
</md-checkbox>
</div>
Dies ist das Format von formationSelection
, nachdem ich meine Form senden Ich möchte, wenn ich mein Formular öffne, um die Checkboxen zu markieren, die in einem Array wie folgt definiert sind:
das Objekt res.candidatureProjetProfessionnel.formations
enthält diese:
formationSelection = [
{
codeFormation: 1,
nom: "ENSA"
},
{
codeFormation: 2,
nom: "CPGE"
}
]
Und wenn ich $scope.formationSelection
inspizieren enthält er die Daten, die ich aus res.candidatureProjetProfessionnel.formations
bekam:
Aber ich weiß nicht, warum sind meine Kontrollkästchen nicht einmal geprüft obwohl die $scope.formationSelection
nicht leer ist.
Wie kann ich das lösen?
'md-checkbox' für Material Design UIs.Bitte sehen Sie dies: https: //material.angularjs.org/latest/demo/checkbox – Sampath
Danke, das hat funktioniert und jetzt brauche ich nicht 'ng-checked =" formationSelection.indexOf (formationType)> -1 "' und weder 'ng-click =" toggleFormationTypeSelection (formationType) ">' –