草庐IT

scope1_method

全部标签

javascript - AngularJS 如何在 2 个或更多 Controller 中解析对 $scope 变量的调用?

Here,作者提到the$scopeobjectusedbythetwocontrollersarenotthesame$scopeobject同样的片段:现在考虑对上面的代码做一点修改。{{data.theVar}}{{data.common}}{{data.theVar}}{{data.common}}{{temp}}{{newTemp}}varmodule=angular.module("myapp",[]);varmyController1=module.controller("myController1",function($scope){$scope.data={theVa

JavaScript 模块模式 : How do private methods access module's scope?

在实现模块模式时,私有(private)函数如何访问模块的私有(private)属性?我还没有看到开发人员这样做的任何例子。有什么理由不这样做吗?varmodule=(function(){//privatepropertyvarnumber=0;//privatemethod_privateIncrement=function(){//howdoIaccessprivatepropertieshere?number++;};//publicapireturn{//OKgetNumber:function(){returnnumber;},//OKincrNumber:function

JavaScript 面向对象 : method definition with or without "prototype"

是这段代码吗,functionPerson(){functionmyMethod(){alert('hello');}this.method=myMethod;}相当于:functionPerson(){}Person.prototype.method2=function(){alert('hello');};如果是,我应该使用哪个方法定义,为什么? 最佳答案 在您的简单示例中,它们在功能上是等效的,但在幕后的工作方式却大不相同。函数的prototype属性实际上是“原型(prototype)模板”。它说“每当创建一个对象并且我被用

javascript - $scope.$on 在 $rootScope.$broadcast 之后不触发

这可能是重复出现的问题,但我找到的针对此问题的解决方法在我的情况下不起作用,这就是我发布问题的原因。我已关注服务:appRoot.service('MyService',function($rootScope){varMessenger={Temp:"",TempId:"",tempMethod:function(Id){TempId=Id;$rootScope.$broadcast('FirstCtrlMethod');}};returnMessenger;});在第二个Controller中:appRoot.controller('SecondCtrl',function($sco

javascript - 有什么方法可以避免使用 JSDoc "@method"注释

我个人不是生成文档的忠实拥护者(我更像是一个“阅读源代码Luke”的人),但我可以看到此类文档对其他人有何用处。现在,通常他们生成的文档不会影响我,除了一件事:@method。大多数JSDoc注释(例如@param)对于阅读源代码的人来说仍然非常有用,但是@method是100%冗余的:/**@paramnumnumbertoaddfiveto*@methodaddFive*/functionaddFive(num){...所以,我真的很想避免让数百行@method弄乱我们的代码。但是,我的同事认为@method是JSDoc生成器(他使用的是YUI生成器)能够生成类的方法列表所必需的。

javascript - 什么时候使用 $scope.$apply() 是安全的?

我想标题已经很清楚我要问什么了。我创建了这个fiddle:http://jsfiddle.net/Sourabh_/HB7LU/13142/在fiddle中,我试图复制一个async场景。这只是一个示例,但在AJAX调用中,如果我不使用$scope.$apply(),则列表不会更新。我想知道每次进行AJAX调用以更新列表时使用$scope.$apply()是否安全,或者是否有其他一些我可以利用的机制?我为复制场景而编写的代码(与fiddle中的相同):HTML{{item.name}}ChangeJSvarmyApp=angular.module('myApp',[]);functio

javascript - 在没有 $scope 的情况下使用 $watch( Controller 作为语法)

在Angular1.3中,可以使用this.foo='bar'代替$scope.foo='bar'。现在,如何在没有$scope的情况下使用$watch? 最佳答案 在使用controlleras语法时,有几个选项可以避免必须使用$watch。以下示例摘自blogpostIwroteaboutavoiding$scope.使用ng-changeIfyouhaveawatchsetuptolistenforapropertychangethatoriginatesfromaformfield,thenng-changeisyourbe

javascript - Angular : Pass $scope variable as directive attribute

我试图将$scope变量值作为属性传递给自定义指令,但它不起作用。这是HTML代码:{{q.question}}指令是,这里是指令代码:app.directive('checkList',function(){return{restrict:'E',template:function(elem,attrs){console.log(attrs.name);return'YesNo'},link:function(scope,elem,attrs){}};})我正在记录属性attrs.name但我得到的值是"{{q.id}}"而不是q.id的实际值 最佳答案

javascript - Internet Explorer 11 : Object doesn't support property or method 'isInteger'

我在InternetExplorer控制台中遇到此错误“对象不支持属性或方法‘isInteger’”,我该如何解决?代码:functionverificaNota(nota){if(nota.length>0){vararr=[];if(nota.indexOf(".")!=-1){returnferificareArrayNote(nota.split('.'));}elseif(nota.indexOf(",")!=-1){ferificareArrayNote(nota.split(','));}elseif(nota.length0){returntrue;}else{retu

javascript - angular-google-maps TypeError : $scope. map.control.refresh 不是函数

我将angular-google-maps集成到我的cordova移动应用程序中。我想使用以下函数刷新map。functionrefreshMap(){$scope.map.control.refresh({latitude:$scope.location.T_Lat_Deg_W.value,longitude:$scope.location.T_Long_Deg_W.value})}但是出现错误angular.js:13540TypeError:$scope.map.control.refreshisnotafunctionatScope.refreshMap(mapControll