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

控制器嵌套的事件发射

时间:2015-05-01 09:20:01      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div ng-app="bb">
    <div ng-controller="abx">
        <ul ng-repeat="names in name track by $index">
            <li ng-bind="names.names"></li>
        </ul>
        <button ng-click="sub()">减</button>
        <span ng-bind="remark"></span>   {{remark}}
        <hr>
        <div ng-controller="aby">
            <button ng-click="add()">加</button>
            <span ng-bind="remark"></span>   {{remark}}
        </div>
    </div>
</div>
</body>
<script src="Angular.js"></script>
<script>
    var app= angular.module("bb",[]);
    app.controller("abx",function($rootScope,$scope){
        $scope.name=[
            {names:"123"},
            {names:"456"},
            {names:"789"},
        ];
        $scope.remark=100;
        $scope.$on("adds",function(event,data){
            $scope.remark+=data;
        });
        $scope.$on("subs",function(event,data){
            $scope.remark-=data;
        });
        $scope.sub = function(){
            $scope.$broadcast("subs",10);
        };
    });

    app.controller("aby",function ($rootScope,$scope){
        $scope.remark=100;
        $scope.add=function(){
            $scope.$emit("adds",10);
        };
        $scope.$on("adds",function(event,data){
            $scope.remark+=data;
        });
        $scope.$on("subs",function(event,data){
            $scope.remark-=data;
        });
    });
</script>
</html>

  

控制器嵌套的事件发射

标签:

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

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