草庐IT

Block-scoped

全部标签

javascript - AngularJs 指令 : call method from parent scope within template

我对Angular指令还很陌生,我很难让它做我想做的事。这是我所拥有的基础知识:Controller:controller('profileCtrl',function($scope){$scope.editing={'section1':false,'section2':false}$scope.updateProfile=function(){};$scope.cancelProfile=function(){};});指令:directive('editButton',function(){return{restrict:'E',templateUrl:'editbutton.t

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 - 是否可以使用 $logProvider 登录模块的配置 block ?

我想在调试时将日志消息输出到控制台。在Controller中工作正常,但无法在模块配置block中工作,例如angular.module('MyApp',[]).run(function($state){//runstuffhere});.config(function($logProvider){$log.debug('Configdebugmessage');});我得到一个错误:errorTypeError:Cannotreadproperty'debug'ofundefined是否可以在模块的配置block中使用logProvider? 最佳答案

javascript - 优化批量( block )将对象上传到 IndexedDB

我想在一个事务中将对象添加到IndexedDB中的某个表中:_that.bulkSet=function(data,key){vartransaction=_db.transaction([_tblName],"readwrite"),store=transaction.objectStore(_tblName),ii=0;_bulkKWVals.push(data);_bulkKWKeys.push(key);if(_bulkKWVals.length==3000){insertNext();}functioninsertNext(){if(ii看起来它工作正常,但它不是非常优化的方

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 - const 已经在 ES6 开关 block 中声明

这个问题在这里已经有了答案:ErrorDuplicateConstDeclarationinSwitchCaseStatement(6个答案)关闭3年前。考虑文件sample.es6switch(1){case1:constfoo=1;break;case2:constfoo=2;break;}如果我用Node运行它,我得到了$node--versionv4.2.11$nodesample.es6/tmp/sample.es6:6constfoo=2;^SyntaxError:Identifier'foo'hasalreadybeendeclaredatObject.(/tmp/sam

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 - 麻烦打印行号和 `alert` ing 长字符串变量来调试 JS 脚本 block

我需要在我的php.html页面中加入一些JS,但我很难调试。我一直在谷歌搜索,但似乎找不到如何打印行号,比如php中的__LINE__。有没有一种方法可以足够轻松地实现这一看似有用的壮举?我遇到的另一个问题是,我正在尝试调试一个不太正常的scriptblock,我需要echo,呃让alert一个很长的字符串的var。不幸的是,警告框自行关闭,大概是因为var字符串太长了。似乎没有为alert框定义参数,例如高度、宽度等,所以我尝试使用这个hack:functionalertDebug(linesToDisable){varnewLinesToDisable=newString();f

javascript - 谷歌地图 API 无法加载 map 图 block

我将googlemapsapiv3嵌入到我的网站中,直到几周前一切正常。在过去的几周内,map瓦片(只有map,卫星瓦片一直工作正常)时不时地无法加载几个小时,有时甚至几天。与此同时,我收到以下两条403错误消息:[Error]Failedtoloadresource:theserverrespondedwithastatusof403(Forbidden)(ViewportInfoService.GetViewportInfo,line0)http://maps.googleapis.com/maps/api/js/ViewportInfoService.GetViewportInf

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

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