草庐IT

scoped_thread

全部标签

javascript - 为什么我的 $scope 属性在我的 AngularJS 应用程序中不断重置?

我有以下AngularJS应用程序,由一个模板(index.html)、一个应用程序定义(app.js)、一个Controller定义(controllers.js)和托管页面(host.jsp)。代码如下:搜索.jsp应用程序.jsangular.module('MyApp',[]).config(['$routeProvider',function($routeProvider){$routeProvider.when('/',{templateUrl:'/index.html',controller:MyController}).otherwise({redirectTo:'/'

javascript - 如何通过 "setInterval"kick ass pass scope

我目前想知道是否有比通过参数'e'将this范围传递给lambda函数然后将其传递给'funkyFunction更好的解决方案'使用call()方法setInterval(function(e){e.funkyFunction.call(e)},speed,this)(撇开小问题:我一直在阅读有关javascript中内存泄漏的内容。lambda函数如何影响我的内存?首先定义它是否更好,如vari=function(e)。..然后将其作为参数传递给setInterval?) 最佳答案 我的情况可能有点不同,但我是这样做的:varse

javascript - Angular JS: '$scope is not defined'

对于AngularJS中的这个Controller代码,我不断收到“$scopeisnotdefined”控制台错误:angular.module('articles').controller('ArticlesController',['$scope','$routeParams','$location','Authentication','Articles',function($scope,$routeParams,$location,Authentication,Articles){$scope.authentication=Authentication;}]);$scope.c

javascript - 在不使用 "angular.element.scope"的情况下从 AngularJs 外部更新范围

我希望能够从Angular外部的函数更新Angular中的范围。例如,如果我有一个返回成功回调的jQuery插件,我希望能够从该成功回调更新范围。我见过的每个解决方案都涉及调用angular.element(selector).scope,然后在返回的范围上调用$apply。但是,我也看到很多评论表明这在调试信息关闭时不起作用,因此不推荐这样做,但我还没有看到任何替代解决方案。有谁知道在不使用angular.element(selector).scope的情况下从Angular外部更新范围的方法吗?这是帖子中接受的解决方案:“如果您想从AngularJs的控制之外对范围值进行任何更改,

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 $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