angluarJs与后台交互get

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{margin: 0;
        padding: 0; list-style: none}
        .con{
            width: 408px;
            height: 300px;margin: 50px auto ;
            border: 1px solid red;  collapse: collapse      }
        .nav:after{
            content: ''; display: block; clear: both;
        }
        .nav li{
            float: left;width: 100px;
            height: 30px;text-align: center;
            line-height: 30px;
            border: 1px solid red;
        }
        #a1 .a1,#a2 .a2,#a3 .a3,#a4 .a4{
            background: aquamarine;
            color: #fff;
        }
    </style>
</head>
<body>
<div class="con" ng-controller="cotr1" ng-init="active='a1'">
    <ul class="nav" id="{{active}}">
        <li ng-click="active='a1'" class="a1">热门</li>
        <li ng-click="active='a2'" class="a2">头条</li>
        <li ng-click="active='a3'" class="a3">财经</li>
        <li ng-click="active='a4'" class="a4">娱乐</li>
    </ul>
    <div ng-show="active=='a1'">
        <ul>
            <li ng-repeat="item in data.a1">
                <a href="{{url}}">{{item.title}}</a>
            </li>
        </ul>
    </div>
    <div ng-show="active=='a2'">
        <ul>
            <li ng-repeat="item in data.a2">
                <a href="{{url}}">{{item.title}}</a>
            </li>
        </ul>
    </div>
    <div ng-show="active=='a3'">
        <ul>
            <li ng-repeat="item in data.a3">
                <a href="{{url}}">{{item.title}}</a>
            </li>
        </ul>
    </div>
    <div ng-show="active=='a4'">
        <ul>
            <li ng-repeat="item in data.a4">
                <a href="{{url}}">{{item.title}}</a>
            </li>
        </ul>
    </div>

</div>
<script src="angular-1.3.0.js"></script>
<script>
    var app=angular.module("myApp",[]);
    app.controller("cotr1",function ($scope,$http) {
      
        $http.get("http://qd.baidu.com/tgr/api/index.aspx?day=82&type=tabs").success(function (data) {
            $scope.data=data;
        })
    });
</script>
</body>
</html>

 

<!DOCTYPE html>
<htmllang="en"ng-app="myApp">
<head>
<metacharset="UTF-8">
<title>Title</title>
<style>
*{margin:0;
padding:0; list-style: none}
.con{
width:408px;
height:300px;margin:50pxauto;
border:1px solid red; collapse: collapse }
.nav:after{
content:''; display: block; clear: both;
}
.nav li{
float: left;width:100px;
height:30px;text-align: center;
line-height:30px;
border:1px solid red;
}
#a1 .a1,#a2 .a2,#a3 .a3,#a4 .a4{
background: aquamarine;
color:#fff;
}
</style>
</head>
<body>
<divclass="con"ng-controller="cotr1"ng-init="active='a1'">
<ulclass="nav"id="{{active}}">
<ling-click="active='a1'"class="a1">热门</li>
<ling-click="active='a2'"class="a2">头条</li>
<ling-click="active='a3'"class="a3">财经</li>
<ling-click="active='a4'"class="a4">娱乐</li>
</ul>
<divng-show="active=='a1'">
<ul>
<ling-repeat="item in data.a1">
<ahref="{{url}}">{{item.title}}</a>
</li>
</ul>
</div>
<divng-show="active=='a2'">
<ul>
<ling-repeat="item in data.a2">
<ahref="{{url}}">{{item.title}}</a>
</li>
</ul>
</div>
<divng-show="active=='a3'">
<ul>
<ling-repeat="item in data.a3">
<ahref="{{url}}">{{item.title}}</a>
</li>
</ul>
</div>
<divng-show="active=='a4'">
<ul>
<ling-repeat="item in data.a4">
<ahref="{{url}}">{{item.title}}</a>
</li>
</ul>
</div>

</div>
<scriptsrc="angular-1.3.0.js"></script>
<script>
var app=angular.module("myApp",[]);
app.controller("cotr1",function($scope,$http){

$http.get("http://qd.baidu.com/tgr/api/index.aspx?day=82&type=tabs").success(function(data){
$scope.data=data;
})
});
</script>
</body>
</html>

posted @ 2019-02-21 16:30  菩提树下的丁春秋  阅读(152)  评论(0编辑  收藏  举报