var app = angular.module("myapp", []);
app.controller("ListController2", ['$scope','getAverage', '$rootScope','postSubAverage',function($scope,getAverage,$rootScope,postSubAverage) {
$scope.subjectAverages = [{
'subjectName': '',
'yearSem': '',
'studentsAppeared': '',
'studentsPassed':'',
'percentage':'',
'average':'',
'facultyComment':'',
'point':''
}];
$scope.calculatePercentage = function(val) {
val.percentage = (parseFloat(val.studentsPassed)*100)/parseFloat(val.studentsAppeared);
$scope.calAverage();
};
$scope.addNew = function(personalDetail) {
$scope.subjectAverages.push({
'subjectName': "",
'yearSem': "",
'studentsAppeared': "",
'studentsPassed':"",
'percentage':""
});
};
$scope.parseFloat = function(value) {
return parseFloat(value);
};
$scope.removeRow=function(index){
// remove the row specified in index
$scope.subjectAverages.splice( index, 1);
$scope.calAverage();
// if no rows left in the array create a blank array
if ($scope.subjectAverages.length() === 0){
$scope.subjectAverages = [];
$scope.calAverage();
}
};
$scope.calAverage=function()
{
var total =0;
angular.forEach($scope.subjectAverages,function(item){
total += item.percentage;
});
$scope.subjectAverages[0].average = (total/$scope.subjectAverages.length).toFixed(2);
if($scope.subjectAverages[0].average>=90)
$scope.subjectAverages[0].point=20;
else if(($scope.subjectAverages[0].average>=80)&&($scope.subjectAverages[0].average<90))
$scope.subjectAverages[0].point=15;
else if(($scope.subjectAverages[0].average>=70)&&($scope.subjectAverages[0].average<80))
$scope.subjectAverages[0].point=10;
else if(($scope.subjectAverages[0].average>=60)&&($scope.subjectAverages[0].average<70))
$scope.subjectAverages[0].point=5;
else
$scope.subjectAverages[0].point=0;
}
$scope.isDisabled = false;
$scope.saveavg=function(){
$scope.isDisabled = true;
$rootScope.progressBarValue=($rootScope.progressBarValue+$scope.subjectAverages[0].point);
$rootScope.progressBar=(10/8)*$rootScope.progressBarValue;
getAverage.subAverage($scope.subjectAverages[0].average);
postSubAverage.postData($scope.subjectAverages);
}
}]);
app.service("postSubAverage",['$http',function($http){
return{
postData:function(subAverage){
$http({
url: '/appraisalform/subaverage',
method: "POST",
data: subAverage,
headers: {
'Content-Type': 'application/json'
}
}).then(function(postData){ //.success is deprecated,so use .then
alert("Updated Successfully");
})
.catch(function(err){//using .catch instead of .error as it is deprecated
console.log("Error in request =>", err)
})
}
}}])
这是.pug代码
角度控制器代码
router.post('/subaverage',function(req,res){
console.log("deepak");
});
当我点击保存按钮时 router.post被解雇
{{1}}
但问题是deepak写的是控制台,但是经过一段时间再次出现
迪帕克
POST / appraisalform / subaverage - - ms - -
迪帕克
我在pug文件中使用angular + javascript。 有人能帮忙吗。 三江源
答案 0 :(得分:0)
可以试试这个:
$scope.saveavg=function(event){
$scope.isDisabled = true;
$rootScope.progressBarValue=($rootScope.progressBarValue+$scope.subjectAverages[0].point);
$rootScope.progressBar=(10/8)*$rootScope.progressBarValue;
getAverage.subAverage($scope.subjectAverages[0].average);
postSubAverage.postData($scope.subjectAverages);
event.preventDefault();
}
因为第二个被调用的可能是本机导航器。 其他想法只使用ng-submi t,而不是使用click和submit。 期待它有所帮助。 TKS