Angular 服务

来源:互联网 发布:逆战弹道优化 编辑:程序博客网 时间:2024/05/17 15:22
<!DOCTYPE html>
<html>


<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/angular.min.js"></script>
</head>


<body ng-app="MyApp" ng-controller="MyCont">
<input type="button" value="请求服务" ng-click="sev()" />
<input type="button" value="设置超时" ng-click="out()" />
<input type="button" ng-model="spa" />
<script>
var mo = angular.module("MyApp", []);
mo.controller("MyCont", function($scope, $http,$timeout,$interval) {
var aa=0;
$scope.sev = function() {
$http.get("http://www.baidu.com").then(function(response) {
alert(response.data.name)
}, function() {
alert("访问失败")
})
}
$scope.out=function(){
$timeout(function(){
alert("倒计时结束")
},3000)
}
$interval(function(){
alert("123");
},1000)
})
</script>
</body>

</html>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title ng-model="tit">呵呵</title>
<script type="text/javascript" src="js/angular.min.js" ></script>
<script type="text/javascript" src="js/jquery-1.11.0.min.js" ></script>
</head>
<body ng-app="MyApp" ng-controller="MyCont">
<p ng-model="p1">{{p1}}</p>
<p ng-model="p2">{{p2}}</p>
<p ng-model="p3">{{p3}}</p>
<p ng-model="p4">{{p4}}</p>
<p ng-model="p5">{{p5}}</p>
<p ng-model="p6">{{p6}}</p>
<p ng-model="p7">{{p7}}</p>
<p ng-model="p8">{{p8}}</p>
<script>
var mo = angular.module("MyApp",[]);
mo.controller("MyCont",function($scope,$location,$window){
$scope.p8="URL地址是:"+$location.absUrl()
$scope.p1="屏幕高度是:"+$window.innerHeight;
$scope.p2="屏幕宽度是:"+$window.innerWidth;
$scope.p3="页面Title是:"+$scope.tit;
$scope.p4="URL协议是:"+$location.protocol();
$scope.p5="URL主机是:"+$location.host();
$scope.p6="端口号是:"+$location.port();
$location.path("aaa");
$scope.p7="设置URL的hash部分:"+$location.path();
})
</script>
</body>
</html>

原创粉丝点击