Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
129 views
in Technique[技术] by (71.8m points)

angular代码差错

控制器代码如下


var myapp1 = angular.module('myApp', []);
  myapp1.controller('wyCtrl', ['$scope','$http',function($scope,$http) {
    $http({
      method:'get',
      url:'/php/search.php'
    }).then(function(response){
      //成功时执行
      console.log(response);
      $scope.items = response.items;
    },function(response){
      //失败时执行
      console.log(response);
    });
}]);

HTML代码如下

        <div ng-controller="wyCtrl" >
                                <ol style="float:left;text-align:left">
                                    <li ng-repeat="x in items">
                                        <div style="font-size:20px;line-height:40px;  ">
                                            {{x.title}}
                                        </div>
                                    </li>
                                </ol>
                                <ul style="float:right;">
                                    <li ng-repeat="x in items" style="list-style-type:none;line-height:40px ">
                                        {{x.time}}
                                    </li>
                                </ul>
                                <script src="namesController.js"></script>
                            </div>

php代码

<?php
$items = [
  ['title' => 'tyz' , 'time' => 'www.baidu.com'],
  ['title' => 'zyt' ,  'time' => 'www.qq.com'],
];
echo json_encode($data,JSON_UNESCAPED_UNICODE);
?>

控制台輸出Cannot read property '1' of null

页面无法显示内容,另外请问如何修改以上代码才能使得前端向php传递参数


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

控制台输出的什么?你查看一下Network看看返回了什么数据,应该是在response.data中。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...