码迷,mamicode.com
首页 > Web开发 > 详细

angularJS平行控制器间共享数据

时间:2015-05-13 08:44:55      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body ng-app="myApp">
    <div ng-controller="c1">
        {{name}} , {{msg}} , {{datas}}
    </div>
    <div ng-controller="c2">
        {{name}} , {{msg}} , {{datas}}
    </div>
</body>
<script src="angular.js"></script>
<script>
    var app = angular.module("myApp",[]);
    //factory和service的最大区别就是service所注入的类型必须为对象而factory可以是任意类型
    app.factory(custData1,function(){
        return{
            message:"共享数据!",
            Data:[a,b,c]
        }
    });
    app.controller("c1", function($scope,custData1){
        $scope.name="123";
        $scope.msg = custData1.message;
        $scope.datas = custData1.Data[1];
    });
    app.controller("c2", function($scope,custData1){
        $scope.name="456";
        $scope.msg = custData1.message;
        $scope.datas = custData1.Data[2];
    });
</script>
</html>

 

angularJS平行控制器间共享数据

标签:

原文地址:http://www.cnblogs.com/zzq-include/p/4499299.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!