<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" >
<title>获取网络数据</title>
<script type="text/javascript" src="js/angular.js" ></script>
<script>
var app=angular.module("myapp",[]);
app.controller("myctrl",function($scope,$location,$timeout,$interval,$http){
$scope.myurl=$location.absUrl();
$scope.a=$location.host();
$scope.b=$location.protocol();
$scope.c=$location.path();
$scope.d=$location.port();
//$timeout
$scope.str="";
$timeout(function(){
$scope.str="我是2秒以后出现";
},2000);
//$initerval
$scope.currentTime="";
$interval(function(){
var _date=new Date().toLocaleTimeString();
$scope.currentTime=_date;
},1000);
//$http
$scope.dataJson="";
/*$http({//请求一个json 本地的
method:"get",
url:"haha.json"
}).then(function success(response){//请求成功了
$scope.dataJson=response.data;
//debugger;
},function error(response){//请求失败了
});
$scope.deleteP=function($index){
$scope.dataJson.splice($index,1);
};*/
//通过http内置服务 请求网络数据 展示
$scope.jsonFromNet="";
$http({
method:"get",
url:"http://result.eolinker.com/pWEDzFn48fd146c3a725c1571f997a44281b94d1201b661?uri=myjson1"
}).then(function success(response){
$scope.jsonFromNet=response.data;
//debugger;
},function error(response){
//debugger;
});
$scope.deleteG=function($index){
$scope.jsonFromNet.data.splice($index,1);
}
});
</script>
</head>
<body ng-app="myapp" ng-controller="myctrl">
<center>
<h3>获取网络 杂 练习</h3>
<p>1 {{myurl}}</p>
<p>2 {{a}}</p>
<p>3 {{b}}</p>
<p>4 {{c}}</p>
<p>5 {{d}}</p>
<p>{{str}}</p>
<p>当前时间: {{currentTime}}</p>
<!--<p>通过http服务获取本地json 展示</p>
<table>
<tr>
<th>序号</th>
<th>名字</th>
<th>年龄</th>
<th>性别</th>
<th>操作</th>
</tr>
<tr ng-repeat="p in dataJson">
<td>{{$index}}</td>
<td>{{p.name}}</td>
<td>{{p.age}}</td>
<td>{{p.sex}}</td>
<td><input type="button" ng-click="deleteP($index);" value="删除"/></td>
</tr>
</table>-->
<p>通过http服务获取网络json 展示</p>
<table>
<tr>
<th>序号</th>
<th>detectionId</th>
<th>detectionItem</th>
<th width="400px">detectionInfo</th>
<th>图片</th>
<th>操作</th>
</tr>
<tr ng-repeat="g in jsonFromNet.data ">
<td>{{$index}}</td>
<td>{{g.detectionId}}</td>
<td>{{g.detectionItem}}</td>
<td>{{g.detectionInfo}}</td>
<td><img src="http://www.sinaimg.cn/ty/deco/2013/1108/nbalogo/20.png"/></td>
<td><input type="button" ng-click="deleteG($index);" value="删除"/></td>
</tr>
</table>
</center>
</body>
</html>
获取网络数据
最新推荐文章于 2022-03-19 15:00:00 发布