【问题标题】:how to access table or variable from php controller in angular js controller如何在 Angular js 控制器中从 php 控制器访问表或变量
【发布时间】:2016-02-27 05:32:46
【问题描述】:

我在 codeignitor 工作。我想从 php 控制器返回表并想在 angular js 控制器中访问它。 这是php控制器的代码。 表格.php

    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');

    class Table extends CI_Controller {

    public function index(){

        $this->load->view('home');


        }
        public function live()
        {
$data=" .<table><tbody><tr> <th> a  </th><th>    b</th><th> c  </th>."
".</tr><tr<td>1</td><td>2</td><td>3</td></tr> </tbody></table> .";
or 
$data="one";

        return $data;
        }

}

这是带有控制器的 route.js 的代码。

var myApp = angular.module('myapp', ['ui.router']);

myApp.config(function($stateProvider, $urlRouterProvider,$locationProvider) {
    $stateProvider

        // HOME STATES AND NESTED VIEWS ========================================
        .state('home',{
            url: '/',
            templateUrl: 'home.html',
//            controller: 'mainctrl'
        })
        .state('live',{

            url:'/live',
            templateUrl: 'partials/show.html',
            controller: 'livectrl'
        })
});
   myApp.controller('livectrl',function($scope,$http,$location,$state){

        $http.get('/live').success(function(res){
         $scope.items=res;
        console.log($scope.items);
        console.log("work");
         $state.go('live');    
        }).
        error(function(err){

            alert(13);
        })

        });

这是 home.php 的代码

<html>
<head>
    <script src="<?php echo base_url(); ?>libs/js/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js"></script>
    <script src="<?php echo base_url(); ?>libs/js/route.js"></script>

</head>
<body ng-app="myapp">
<div ng-controller="livectrl">
 <div ui-view=""></div>
</div>

</body>
</html>

当调用 livectrl 时,我在“localhost/tcric”中列出应用程序它在警报“13”中返回错误。 我如何从 php 控制器返回数据并在 Angular js 控制器中访问它。

【问题讨论】:

    标签: php html angularjs codeigniter angular-ui-router


    【解决方案1】:

    不要从 php 制作表格数据。 ajax 调用的最佳方法是返回表行数组,然后在角度应用程序中使用 ng-repeat 生成此表行。

    【讨论】:

      猜你喜欢
      • 2017-09-22
      • 2016-02-17
      • 1970-01-01
      • 2023-03-10
      • 2012-02-21
      • 2015-12-14
      • 1970-01-01
      • 1970-01-01
      • 2017-03-23
      相关资源
      最近更新 更多