草庐IT

scope-chain

全部标签

javascript - 以推荐的方式停止 Promise Chain 执行

这个问题在这里已经有了答案:Howtoproperlybreakoutofapromisechain?(3个答案)关闭5年前。我有一个类似于这个的代码:promise_function().then(()=>{//dosomethingreturnanother_promise_fucntion();}).then(()=>{//dosomethingreturnanother_promise_function1();}).then((result)=>{//checkifresultisvalidif(!result)//breakchain(howtostopcallingthen

javascript - 调试显示模块模式 : functions not in scope until called?

如果我在Chrome开发者工具中运行这段代码:vartest=(function(){varpublicFunction,privateFunction1,privateFunction2;privateFunction1=functionprivateFunction1(){returntrue;};privateFunction2=functionprivateFunction2(){returntrue;};publicFunction=functionpublicFunction(){privateFunction1();debugger;};return{publicFunc

javascript - Angular : chaining promises over forEach loop

我无法理解promise。我正在使用GoogleEarthAPI进行地址“游览”。游览只是一个持续大约一分钟的动画,一个完成后,下一个应该开始。这是我的巡视功能:vartourAddress=function(address){returntourService.getLatLong(address).then(function(coords){returntourService.getKmlForCoords(coords).then(function(kml){_ge.getTourPlayer().setTour(kml);_ge.getTourPlayer().play();v

javascript - Angular $scope 不会在 bootbox 回调中更新

这是我关于SO的第一个问题。当我在作用域上拼接一个数组元素时,在bootbox.js的回调中完成时,该更改不会反射(reflect)出来。作品:$scope.deleteA=function(){if(confirm("ReallydeleteItem3?")){$scope.itemsA.splice(2,1);}}不起作用:$scope.deleteB=function(){bootbox.confirm("ReallydeleteItem3?",function(answer){if(answer===true){$scope.itemsB.splice(2,1);}});}我主

javascript - AngularJS 指令 : compile template and watch scope

我在Angularjs上编写了一个非常复杂的应用程序。这已经大到让我感到困惑了。我对Angular进行了更深入的研究,发现我的代码很糟糕。我理解这个概念:module.directive('createControl',function($compile,$timeout){scope:{//scopebindingswith'='&'@'},template:'Templatestringwithbinded{{variables}}',link:function(scope,element,attrs){//Functionwithlogic.Shouldwatchscope.}我

javascript - $scope 的方法通过 ng-click 调用 : executed twice by IE

在我的Controller中:$scope.homeAction=function(){console.log("HomeAction");};在我看来:callhomeAction()单击按钮时,Chrome和Firefox会按预期执行该方法,但IE会执行两次。知道为什么吗?这是一个重现问题的plunker:http://plnkr.co/edit/pedZKjIVGDAYfMl0ZphJ. 最佳答案 只需将type="button"添加到您的按钮,它就会被修复。默认行为是提交,这显然会扰乱您的代码。callhomeAction(

javascript - 我应该总是将函数绑定(bind)到 $scope 对象吗?

当我创建Controller时,我总是将函数添加到$scope对象,像这样:functionDummyController($scope){$scope.importantFunction=function(){/*...*/};$scope.lessImportantFunction=function(){/*...*/};$scope.bussinessLogicFunction=function(){/*...*/};$scope.utilityFunction=function(){/*...*/};}当然,我会很好地封装我的Controller,确保业务逻辑位于适当的组件(通

javascript - 使用 Jasmine 2.0 对 $scope.$evalAsync 函数进行单元测试

我正在尝试对$scope.$evalAsync函数进行单元测试。这是我的代码:$scope.$evalAsync(function(done){//enablethepopoverplugindone();jQuery('[data-toggle="popover"]').popover();$scope.isKioskIdLoaded.state=true;});我很难理解如何让evalAsync在我的Jasmine测试中运行。我正在尝试利用Jasmine2.0中的done()函数。 最佳答案 您需要将$scope.$digest

javascript - $scope.$on ('$destroy' , ...) 的事件处理程序是否被销毁?

今天遇到了一个非常“深奥”的Angular问题,我找不到答案。来自$scope文档,您可以在"$destroy"上注册一个事件处理程序,它会在作用域销毁之前立即调用。这样,您就可以像这样注销事件处理程序:varderegister=$scope.$on('myCustomEvent',function(){//dosomecrazystuff});$scope.$on('$destroy',function(){deregister();});但是,$scope.$on('$destroy',...)必须创建自己的处理程序。它是自动销毁的,还是必须执行以下操作才能销毁它?vardere

javascript - 在指令中调用 $compile($element)($scope) 的目的是什么

Angular码placedonjsfiddle关于自定义指令,它使用$compile($element)($scope)并导致ng-click操作发生两次:我的问题是:我想了解为什么会发生ng-click操作两次?调用$compile($element)($scope)的目的是什么?如果不调用会发生什么,在什么情况下应该调用叫什么?以下是详细信息以及我目前收集到的信息:我想明白,为什么ng-clickAction会发生两次?下一行显示了自定义指令“hello”和ng-click按钮。自定义指令调用$compile($element)($scope)并且这是导致操作被触发两次的行,但我