angularjs自定义服务

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="../css/angular.min.js" ></script>
<script>
var app=angular.module("app",[]);

//引用:自定义的服务 时间间隔 时间计时服务
app.controller("mycon",["$scope","$http","$interval","$timeout","myfactory",function($scope,$http,$interval,$timeout,myfactory){
$scope.show=function(){
$http.get("../stars.json").then(function(dat){
$scope.inData=dat.data;
console.log(dat.data);
});
}

$scope.timeshow=function(){

//时间计时器服务
$scope.stop=$interval(function(){
$scope.datae=new Date();
},1000);
};
// 停止计时器 
$scope.stopshow=function(){
$interval.cancel($scope.stop);
}
$scope.time=myfactory;
}]);

//自定义服务
app.factory("myfactory",["$filter",function($filter){
var time=new Date();

return $filter('date')(time,'mm:ss');

}]);

//<!--  自定义指令-->
app.directive("mydirective",function(){
return{
//E ----元素标签   <gaoyn></gaoyn>   --->hello gaoyn
//C---类元素名(class="gaoyn")      ----hello gaoyn
//A---属性        <div gaoyn> </div>   ----hello gaoyn
//M---注释          <!-- directive:gaoyn -->  
/*****默认A*******/
restrict : "MAEC" ,
replace: true,
template : '<P>zai</P>'

}

})
</script>
</head>
<body ng-app="app" ng-controller="mycon">
<button ng-click="show()">查看数据</button>
<table>
<tr ng-repeat="kk in inData">
<td>{{kk.name}}</td>
<td>{{kk.age}}</td>
<td>{{kk.sex}}</td>
<td>{{kk.ablum}}</td>


</tr>
</table>
<button ng-click="timeshow()">计时器</button>
<button ng-click="stopshow()">停止</button>
<p>{{time}}</p>
<p>{{datae | date :'mm:ss'}}</p>

<!--  自定义指令-->
<!--  E ----元素标签-->
<mydirective></mydirective>
<!-- C 添加的类样式-->
<p class="mydirective"></p>
<!--A---属性        <div gaoyn> </div> -->
<p mydirective></p>
<!--M---注释    -->
<!-- directive:mydirective -->
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值