【问题标题】:fetching DB record using angular js in codeigniter在codeigniter中使用angular js获取数据库记录
【发布时间】:2017-08-19 15:18:00
【问题描述】:

请帮助我新的 Angular js 我执行插入操作现在试图检索数据,我只是搞砸了。没有收到任何错误,但我的表格在浏览器中是空白的。 控制台也没有错误。 现在需要更改或更新什么? 我分享了我的代码,请查看并帮助我。

App.js:

var myapp = angular.module('myApp', []);
(function(app)
{
    myapp.controller("ViewController", ['$scope','$http', function($scope, $http ) 
    {
        $scope.results = [];
        $http({
            method: 'GET',
            url:'http://localhost/ngci/user/view'
        }).then(function (data, status) 
        {
            $scope.results = data;
        });
    }]);
})(myapp);

控制器:

 public function view()
 {
    $data['x'] = $this->user_model->viewusers();
    
    $this->load->view('view_data',$data);
 }

查看:

<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="<?php echo base_url(); ?>angular/app.js"></script>
</head>
<body>

<div id="container" ng-app="myApp" ng-controller="ViewController">
<table class="table table-bordered"> 
<thead>
    <th>name </th>
    <th>city</th>
</thead>
<tbody>
    <tr ng-repeat="x in results">
        <td>{{ x.name }}</td>
        <td>{{ x.city }}</td>
    </tr>
</tbody>
</table>
</div>
</body>
</html>

【问题讨论】:

  • 你收到后端的响应了吗?
  • 我在控制器中使用 print_r($data) 时正在获取记录。
  • @ankit suthar ,如果你知道答案,请帮助我。
  • 当然想帮忙,但我没有更多地使用角度。
  • 看到这可能会有所帮助link1

标签: javascript php angularjs codeigniter


【解决方案1】:

不是角度专家,但尝试以 JSON 格式发送数据。这是控制器代码:

public function view() {
    $data = $this->user_model->viewusers();     
    $this->output->set_content_type('application/json')->set_output(json_encode($data));
}

看到这个Example Link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-11
    • 1970-01-01
    相关资源
    最近更新 更多