Angular 学习笔记——模块之间的通讯

<!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('module1',[]);
// m1.factory('myService',function (){
//     return{
//         name:'hello',
//         show:function(){
//             return this.name + ':angular';
//         }
//     };
// });

m1.provider('myService',function(){
    return{
        name:'hello',
        $get:function(){
            return{
                name:this.name,
                show:function(){
                    return this.name + ':angular'
                }
            }
        }
    }
})
var m2 = angular.module('myApp',['module1']);

m2.controller('Aaa',['$scope','myService',function($scope,myService){
    console.log(myService.show())
}])
</script>
</head>

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

 

posted @ 2015-12-09 00:34  mayufo  阅读(754)  评论(0编辑  收藏  举报