标签:
<!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