您的位置:首页 > Web前端 > AngularJS

Angular 学习笔记——service &constant

2015-12-09 00:44 666 查看
<!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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: