/ / Ustawienie zmiennej w ng-repeat - angularjs

Ustawianie zmiennej w ng-repeat - angularjs

Próbuję stworzyć interfejs graficzny dlaaktualizowanie wpisów bazy danych za pomocą metody angular.js. Moja obecna strategia polega na utworzeniu formularza dla każdego wpisu, który można wyświetlić za pomocą polecenia ng-hide. Obecnie mam trudności z uzyskaniem dostępu do informacji wprowadzonych do formularza.

Aktualny kod jest następujący:

admin-edit.html:

<div ng-app= "routerApp" ng-controller="FormCtrl">
<div ng-repeat = "question in multChoice" class = "question" required>
<div class = "col-md-12">
<label>Title: {{question.title}}</label>
<br>
<label>Type: {{question.type}}</label>
<br>
<label>Key: {{question.key}}</label>
<br>
<label>Options:</label>
<br>
<div ng-repeat = "option in question.options" class = "likert">
<input type = "radio" name = "{{question._id}}" value = "{{option.value}}" ng-model = "question.userChoice"> {{option.text}}</input>

</div>
</div>
<button ng-click = "edit = !edit; currentQuestion = question">Edit</button>
<div ng-show = "edit">
<br>
<input type = "text" ng-model = "title" >Title</input>
<br>
<input type = "text" ng-model = "type">Type</input>
<br>
<input type = "text" ng-model = "key">Key</input>
<br>
<input type = "text" ng-model = "op1">Option 1</input>
<br>
<input type = "text" ng-model = "op2">Option 2</input>
<button ng-click = "editQuestion(); edit = false">Submit</button>
</div>
</div>
</div>

odpowiednie bity formCtrl:

$scope.currentQuestion;
$scope.question;
$scope.title;
$scope.key;
$scope.type;

$scope.editQuestion = function(){
console.log($scope.currentQuestion);
if($scope.title == "" || !$scope.title){
$scope.title = $scope.currentQuestion.title;
}

if($scope.key == "" || !$scope.key){
$scope.key = $scope.currentQuestion.key;
}

if ($scope.type == "" || !$scope.type){
$scope.type = $scope.currentQuestion.type;
}

$scope.question.title =$scope.title;
$scope.question.key = $scope.key;
$scope.question.type = $scope.type;

questions.update($scope.question);
}

Obecnie wydaje się, że $ scope.currentQuestion nigdy nie zostanie przypisane; jest niezdefiniowany. Jak mogę ustawić currentQuestion w jego zasięgu podrzędnym?

Odpowiedzi:

0 dla odpowiedzi № 1

Być może upraszczam rzeczy, ale uważam, że inicjowanie $ scope.currentQuestion rozwiąże problem, jak w:

$scope.currentQuestion = {} ; // or load it from somewhere??