Answer the question
In order to leave comments, you need to log in
How to send a post request to change data in MySQL using Angular 2+?
Hi friends!
I want to make an application in Angular (version 4). The application also plans to work with the database (MySQL), backend - php.
I found one example, but it is for Angular 1:
in the main.html file there is such a code that I would like to rewrite, according to the innovations of Angular 2+, but so far I could not figure out how to do it and I hope for your hints / examples:
<script>
var app=angular.module('myApp',[]);
app.controller('cntrl', function($scope,$http){
$scope.obj={'idisable':false};
$scope.btnName="Insert";
$scope.insertdata=function(){
$http.post("insert.php",{'id':$scope.id, 'name':$scope.name, 'btnName':$scope.btnName})
.success(function(){
$scope.msg="Data Inserted";
$scope.displayStud();
})
}
$scope.displayStud=function(){
$http.get("select.php")
.success(function(data){
$scope.data=data
})
}
$scope.deleteStud=function(studid){
$http.post("delete.php",{'id':studid})
.success(function(){
$scope.msg="Data Deletion successfull";
$scope.displayStud();
})
}
$scope.editStud=function(studid, studname)
{
$scope.id=studid;
$scope.name=studname;
$scope.btnName="Update";
$scope.obj.idisable=true;
$scope.displayStud();
}
});
</script>
Answer the question
In order to leave comments, you need to log in
As for this entry - "ng-click="insertdata()" " - it's just a function call here.
For example, on Angular 2, it will be like this:
<div (click)='insertdata()'>Событие клик по нажатию на этот блок вызывает функцию insertdata</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question