将angularjs表连接到数据库时出现问题

时间:2019-07-05 09:23:13

标签: javascript php mysql angularjs

我是编码和尝试从数据库将数据插入angularjs表中的新手。这是我正在处理的代码:

<html>
 <head>
  <title>AngularJS PHP CRUD</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.8/angular.min.js"></script>  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="bootstrap.min.css"> 
 </head>
 <body>
     <div class="container" ng-app="liveApp" ng-controller="liveController" ng-init="fetchData()">      
<br/>
<h3 align="center">CRUD table</h3> <br/>
    <div class="table-responsive" style="overflow-x: unset;">
        <table class="table table-bordered table-striped">
        <thead>
        <tr>
            <th>First Name</th>
           <th>Last Name</th>
           <th>Action</th>
        </tr>
        </thead>
        <tbody>
            <tr ng-repeat="data in namesData" ng-include="getTemplate(data)">                              
            </tr>
        </tbody>
        </table>
<script type="text/ng-template" id="display">
    <td>{{data.first_name}}</td>
    <td>{{data.last_name}}</td>
    <td>
        <button type="button" class= "btn btn-primary btn-sm">EDIT</button>
        <button type="button" class= "btn btn-danger btn-sm">DELETE</button>
    </td>
</script>
<script type="text/ng-template" id="edit">
    <td><input type= "text" ng-model="formData.first_name" class="form_control"/></td>
    <td><input type= "text" ng-model="formData.last_name" class="form_control"/></td>
    <td><input type= "hidden" ng-model="formData.data.id"/>
    <button type="button" class= "btn btn-info btn-sm">Save</button>
    <button type="button" class= "btn btn-default btn-sm">Cancel</button></td>
</script>
    </div>
</body>
</html>
<script>
var app= angular.module('liveApp',[]);
app.controller=("liveController",function($scope,$http)
{
    $scope.fetchData=function(){
        $http.get('select.php').success(function(data)
        {
            $scope.namesData=data;
        })
    };
    $scope.getTemplate=function(data)
    {
        if(data.id==$scope.formData.id)
        {
            return 'edit';
        }
        else
        {
            return 'display';
        }
    };
});

,我只能看到没有任何内容的表。我从这里开始遵循一个教程:https://www.youtube.com/watch?v=2-IZAzf97Zg,如果有人帮助我解决此问题,我将非常感激。

0 个答案:

没有答案