天天看点

Angular.js用法(三):ajax获取数据并循环显示

<?php

$news=[
    '人民币贬值',
    '黄金涨价',
    '楼市崩盘',
    ];
echo json_encode($news);

?>      
<html>  
<head>
<meta charset="utf-8">
    <script src="https://cdn.bootcss.com/angular.js/1.5.8/angular.min.js"></script>
</head>
<body>
<h1>angular获取新闻,并放在li里面</h1>
 <ul ng-app="news" ng-controller="contro">
    <li ng-repeat="n in news">{{n}}</li>
 </ul>
<script>var app = angular.module('news',[]);
    app.controller('contro',function($scope,$http){
        $http.get('news.php').success(function(res){</script>
</body>
</html>