本文介绍了谁能帮我这个? $ js中的$ emit和$ on的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! < div ng-app = myModule class = col-md-12 > < div ng-controller = FirstController > < 输入 type = text class = 表单控件 ng-model = 名称 / > < / div > < div ng-controller = SecondController > < 输入 type = text class = 表格控制 ng-model = inputText / > < 按钮 class = btn btn-primary ng-click = callDisp() > 点击我< /按钮 > < / div > < / div > var myModule = angular.module(myModule,[]); myModule.controller(FirstController,['$ scope',函数($ scope){ $ scope.name; $ scope。$ on (myEvent,function(event,args){ $ scope.name = args.name; // $ scope.disp(); }); $ scope.disp = function() { // alert($ scope.name); } }]); myModule.controller(SecondController,['$ scope',函数($ scope){ $ scope.inputText; $ scope.callDisp = function() { $ scope。$ emit(myEvent,$ scope.inputText); } }]); 解决方案 scope',function( scope){ scope.name; <div ng-app="myModule" class="col-md-12"> <div ng-controller="FirstController"> <input type="text" class="form-control" ng-model="name" /> </div> <div ng-controller="SecondController"> <input type="text" class="form-control" ng-model="inputText" /> <button class="btn btn-primary" ng-click="callDisp()" >Click Me</button> </div></div>var myModule = angular.module("myModule", []);myModule.controller("FirstController", ['$scope', function ($scope) { $scope.name; $scope.$on("myEvent", function (event, args) { $scope.name = args.name; // $scope.disp(); }); $scope.disp=function() { // alert($scope.name); }}]);myModule.controller("SecondController", ['$scope', function ($scope) { $scope.inputText; $scope.callDisp=function() { $scope.$emit("myEvent", $scope.inputText); }}]); 解决方案 scope', function (scope) {scope.name; 这篇关于谁能帮我这个? $ js中的$ emit和$ on的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 11:27