控制器代码如下
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传递参数
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…