K
K
Konstantin2017-06-12 18:07:01
PHP
Konstantin, 2017-06-12 18:07:01

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>

Please, if you are not in the subject, then you don’t just need to pour links to the official documentation without any explanation, this will definitely be of no use.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Moskalenko, 2017-06-12
@Alexinger

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 question

Ask a Question

731 491 924 answers to any question