Database access with Angular

后端 未结 3 1318
自闭症患者
自闭症患者 2021-02-10 05:23

Is it possible to access MySQL databases in Angular framework or would that be insecure like other Javascript and I will need to post to a PHP page to retrieve data/json

3条回答
  •  情歌与酒
    2021-02-10 06:04

    // Application module
    var dbApp = angular.module('dbApp',[]);
    dbApp.controller("DbController",['$scope','$http', function($scope,$http){
    
    // Function to get data from the database
    getDatafromDatabase();
    function getDatafromDatabase(){
    // Sending request to php files
    $http.post('databaseFiles/yourfile.php').success(function(data){
    // Stored the returned data into scope
    $scope.dbData = data;
    });
    }
    

    And php file which we want to call in angularjs script (yourfile.php)

     
    

    HTML file look like this

     
    ...
    
    
    ...
    Column1 Column2 Column3 Column4 Column5
    {{dbData .Column1}} {{dbData .Column2}} {{dbData .Column3}} {{dbData .Column4}} {{dbData .Column5}}

    I hope it helps you

提交回复
热议问题