首页 > 其他 > 详细

Angular 学习笔记——service &constant

时间:2015-12-09 01:53:40      阅读:131      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE HTML>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="angular.min.js"></script>
<script>
var m1 = angular.module(‘myApp‘,[]);
m1.service(‘myService‘,FnService);
function FnService(){
    this.name = ‘hello‘
}
FnService.prototype.age = 20;

m1.controller(‘Aaa‘,[‘$scope‘,‘myService‘,function($scope,myService){
        console.log(myService.name);
}])

</script>
</head>

<body>
<div ng-controller="Aaa">
   
</div>
</body>
</html>

 

<!DOCTYPE HTML>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="angular.min.js"></script>
<script>
var m1 = angular.module(‘myApp‘,[]);
// m1.service(‘myService‘,FnService);
// function FnService(){
//     this.name = ‘hello‘
// }
// FnService.prototype.age = 20;

m1.constant(‘myService‘,‘hello angular11‘);

m1.config([‘myService‘,function(myService){
    console.log(myService);
}])
m1.controller(‘Aaa‘,[‘$scope‘,‘myService‘,function($scope,myService){
        console.log(myService);
}])

</script>
</head>

<body>
<div ng-controller="Aaa">
   
</div>
</body>
</html>

 

Angular 学习笔记——service &constant

原文:http://www.cnblogs.com/mayufo/p/5031602.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!