使用ionic angularjs,尝试传递我的值以将其上传到服务器 Nots:上传工作但只是默认值,如果我使用默认值更改值stil上传
我的HTML
<section class="item" ng-repeat="survey in surveys.questions">
<p>{{survey.displayTitle}} <i class="fa fa-check" aria-hidden="true"></i></p>
<div class="range">
<i class="icon ion-sad"></i>
<input type="range" min="{{min}}" max="{{max}}" name="range" id="{{survey.id}}" ng-model='modelValue'>
<span class="modelValue">{{modelValue}}<span></span></span>
<i class="icon ion-happy"></i>
</div>
</section>
<button class="button button-block button-assertive" ng-click="survey(modelValue)">
<span ng-hide="loading">Submit <i class="fa fa-paper-plane" aria-hidden="true"></i></span>
<span ng-show="loading">Please wait <i class="fa fa-spinner fa-spin"></i></span>
</button>
我的控制器
app.controller('surveyController', function($scope, $state, $http, $rootScope, Authorization, sharingDataService, $localStorage, $location){
if (sharingDataService.getUser()) {
$scope.user = sharingDataService.getUser().data.accounts[0];
}
$scope.$on('getUserInfo', function(){
$scope.user = sharingDataService.getUser().data.accounts[0];
});
$scope.min = 0;
$scope.max = 6;
$scope.modelValue = 3;
// get survey url
$http.post(sharingDataService.getApiUrl() + '/app/survey/get').then(
function (data) {
$scope.surveys = data.data.survey[0];
}
);
$scope.loading = false;
// on click survey
$scope.survey = function(modelValue){
$scope.loading = true;
// post survey question to database
var obj = $scope.surveys.questions;
var answers = [];
var questionId = 1;
angular.forEach(obj, function(value, key) {
value.modelValue = modelValue;
answers.push({"questionId" : questionId, "value" : value.modelValue});
console.log({"questionId" : questionId, "value" : value.modelValue});
questionId++;
});
$http.post(sharingDataService.getApiUrl() + '/app/survey/saveAnswers', {
"answers" : answers}
).then(function (data) {
$state.transitionTo('thanks');
console.log(answers);
});
}
});
作者注释:如果我添加到ng-model ='survey.modelValue'一切正常,但是在前端你看到输入范围被禁用,用户必须移动它才能获得值。我主要是没有默认值添加