草庐IT

has-scope

全部标签

javascript - react : Get initialstate after state has changed

是否有可能在状态改变后检索初始状态?例如:React.createClass({getInitialState:function(){return{foo:'bar'}},componentWillMount:function(){this.setState({foo:'foo'})},componentDidMount:function(){//gettheinitialstate"bar"?}})我在文档中找不到任何内容。我当然可以将值保存在外部变量中,但我只是好奇是否可以将初始状态视为可以重复使用的“配置”对象。 最佳答案 不

javascript - leaflet.js : Fire event when setView() has finished the animation. 这怎么可能?

我目前正在使用leaflet.js,我现在正在网上搜索很多,以找出:如果有一个事件,可以在异步函数setView()的动画结束后触发。这是我尝试过的:map.setView([lat,lon],12,{pan:{animate:true,duration:0.5},zoom:{animate:true},animate:true}.on('ready',function(e){console.log("animationfinished!");});setView-command完美运行,但是本地图动画准备就绪时应该触发的函数不起作用。有没有人有解决办法?

javascript - 在 grunt 上运行 Karma 时出现警告 'The API interface has changed'

从grunt任务运行karma时,我收到以下警告:Running"karma:unit"(karma)taskWarning:Theapiinterfacehaschanged.Pleaseuseserver=newServer(config,[done])server.start()instead.Use--forcetocontinue.Abortedduetowarnings.我已经使用我的配置测试了运行karma,都使用“运行”和“启动”karma命令,它们似乎工作正常。使用grunt--force可以完成任务,但完成时会出现警告。这是我目前使用的版本:karma0.13.0咕

javascript - 什么触发 "Internet Explorer has modified this page to help prevent cross-site scripting."?

我正在尝试针对InternetExplorer中缺少的CORS功能实现解决方法。对于GET请求我使用JSONP,这里没问题。对于小型POST/DELETE/PUT请求,我还通过GET隧道化请求来使用JSONP,但这不适用于较大的请求(因为GETURL的长度是有限的)。因此,对于大数据,我尝试通过iframe实现表单POST。由于同源策略,我无法读取此POST的响应,因此我在发布数据后通过JSONPGET请求获取响应。效果很好,但有时我会在IE9中收到奇怪的警告:InternetExplorerhasmodifiedthispagetohelppreventcross-sitescrip

javascript - AngularJS:$scope 与此:$scope 的用途是什么?

我在AngularJSstyleguide中找到了这个Preferusingcontrollerassyntaxandcapturethisusingavariable:这意味着我可以通过这个将我的所有功能和模型分配给Controller,并通过View中的别名进行访问。如果这样做,我发现我真的不再需要$scope了。一个异常(exception)是当我想访问$rootScope中的内容时。因此,考虑到引用的建议,如果我对访问$rootScope中的任何内容不感兴趣,我应该什么时候使用$scope?也就是说,我是否应该将所有内容都移动到Controller的this中?如果不是,那么什

javascript - 如何将 $scope 对象注入(inject)对话框模板?

我有这个plunker基于此example,带有一个使用选项对象的resolve属性的对话框示例.基本上我想做的是传递要在对话框模板中使用的标题变量:vartitle="azerty";使用对话框选项对象的解析属性:resolve:{title:angular.copy(title)}然后将其注入(inject)对话框Controller并将其分配给$scope变量:controllers.DialogController=function($scope,dialog,title){$scope.title=title;但是我得到这个错误:Error:Unknownprovider:a

javascript - Uncaught ReferenceError : $scope is not defined

加载页面时收到错误。我正在尝试将一个新对象附加到条目数组。代码有什么问题?index.html抽奖员{{entry.name}}抽奖.jsangular.module('myApp',[]).controller("RaffleCtrl",function($scope){$scope.entries=[{name:"Larry"},{name:"Curly"},{name:"Moe"}]});$scope.addEntry=function(){$scope.entries($scope.newEntry)$scope.newEntry={}}; 最佳答案

javascript - 未捕获的类型错误 : Cannot set property style of#<HTMLElement> which has only a getter

以下代码在Chrome、Safari中失败,在Firefox中运行良好"usestrict";document.body.style="background-color:green;";backgroundshouldbegreen删除“usingstrict”,它起作用了。这是Chrome和Safari中的错误还是Firefox中的错误?MDNsayssettingthestyleisvalid. 最佳答案 问题并非所有浏览器都支持将包含CSS声明block文本表示的字符串分配给style属性。element.style=styl

javascript - Angular.js getElementById() 在 $scope 函数中不起作用

el=document.getElementById(id);在下面的函数内部时不起作用...el为空。在浏览器调试中,我可以使用相同的代码提取元素。我是Angular.js的新手。我不能在附加到作用域的函数中使用常规javascript吗?myappApp.controller('Scroller',function($scope,$location,$anchorScroll){$scope.scrollTo=function(id){el=document.getElementById(id);} 最佳答案 我认为DOM尚未加

javascript - 是否有 'angular.element($0).scope()' 的 Angular 2 等价物

因此,出于我的罪过,我正在进行Angular2项目。我在旧的Angular1工作中一直使用angular.element($0).scope()来检查一个元素,并在开发工具中查看当时范围内的内容。这非常有用,Angular2中有类似的东西吗? 最佳答案 Augury是一个很好的建议。如果你想直接访问使用ng.probe($0)另见GetComponentReffromDOMelementHowtoaccessthe*angular2*components'datainthebrowser'sconsole?howtoaccessAn