码迷,mamicode.com
首页 > 其他好文 > 详细

Angular 学习笔记——service &constant

时间:2015-12-09 01:55:55      阅读:146      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!