草庐IT

has-scope

全部标签

javascript - 更新嵌套 $scope 数组时,Angular.js View 不会更新

我试图在添加评论时让angular.jsView自行更新。我的代码如下:{{comment.user}}{{comment.message}}10minutesago范围在输入时更新:$('.addComment').keypress(function(e){if(e.which==10||e.which==13){$scope.currentItem.comments.push({"user":"user3","message":$(this).val()});console.debug("currentItem",$scope.currentItem);}});调试$scope.c

javascript - AngularJS 1.4 指令 : scope, 两种方式绑定(bind)和 bindToController

Update:Itmusthavebeensomethingstupidinanotherpartofthecode.Itworksnow,sothebindToControllersyntaxisfine.我们正在使用AngularJS1.4,它引入了一个newwaytousebindToController在指令中。经过相当多的阅读(也许还没有完全理解),我们这样定义了我们的指令:.directive('mdAddress',functionmdAddress(){vardirective={restrict:'EA',scope:{},bindToController:{addr

javascript - 如何将使用 $scope 的函数包含/注入(inject)到 angularjs 的 Controller 中?

我正在尝试将工厂中保存的函数库包含到Controller中。类似于这样的问题:Creatingcommoncontrollerfunctions我的主Controller是这样的:recipeApp.controller('recipeController',function($scope,groceryInterface,...){$scope.groceryList=[];//...etc.../*tryingtoretrievethefunctionshere*/$scope.groceryFunc=groceryInterface;//wouldcallng-click="gr

javascript - 错误 : attempted to update component that has already been unmounted (or failed to mount)

我是React的新手,由于这个错误,我无法呈现我的应用程序。由于尝试在卸载时设置状态,我试图呈现为元素的数据似乎不会呈现?我不确定我是怎么得到这个错误的,因为我正在componentDidMount中设置Data的状态。我该如何解决这个问题?error:attemptedtoupdatecomponentthathasalreadybeenunmounted(orfailedtomount)classProfileextendsReact.PureComponent{staticpropTypes={navigation:PropTypes.object,handleLogout:Pr

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 - $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 - 什么时候使用 $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 object.hasOwnProperty(proName) vs lodash _.has(obj, proName) 函数

我正在争论是使用JavaScriptObject.hasOwnProperty(propName)还是使用lodash_.has(obj,proName)函数来确定对象是否具有属性。对于简单的情况,哪个更有效?对于复杂的情况?对于所有情况?有没有我没有提到的更好的库?谢谢! 最佳答案 Lodash_.has()方法只是在检查空参数后调用Object.prototype.hasOwnProperty()。代码很早就获取了引用:varhasOwnProperty=Object.prototype.hasOwnProperty;然后_.h

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

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