草庐IT

scope-chain

全部标签

javascript - 使用 `this.$watch` 而不是 `$scope.$watch` 和 'Controller As'

目前我正在使用ControllerAs格式来定义范围Controller。这对于保持View上的值范围清晰且易于遵循非常有效。但是,在实现$watch时我遇到了问题,因为它似乎依赖于$scope,所以下面的代码将不起作用。angular.module('myApp',[]).controller('myController',['contacts',function(contacts){this.contacts=contacts;this.$watch('contacts',function(newValue,oldValue){console.log({older:oldValue

javascript - 如何使用underscore 的chain 方法返回多维数组中的第一项?

假设我有一个数组数组,我想返回数组中每个数组的第一个元素:array=[[["028A","028B","028C","028D","028E"],["028F","0290","0291","0292","0293"],["0294","0295","0296","0297","0298"],["0299","029A","029B","029C","029D"],["029E","029F","02A0","02A1","02A2"]],[["02A3","02A4"],["02A5","02A6"]];我知道我可以做这样的事情:varfirsts=[];_.each(array,

javascript - 范围链查找与原型(prototype)查找 - 哪个是什么时候

如果一个变量在需要时在函数中不可用,那么它会在作用域链(它是一个闭包)中查找,但其他时候它会在原型(prototype)链中查找。我正在努力思考什么时候发生。我想知道是否有人可以为我拨开迷雾,或者让我引用一些专门讨论这个主题的文献。例如,我这样说是否正确:-对象和因此绑定(bind)到上下文(this)的公共(public)变量总是在原型(prototype)链中查找?-始终在作用域链中查找私有(private)变量(即执行上下文中的函数链)?-是否存在程序同时查看/查看其中一个的情况?我测试了三种不同的场景(作用域链查找、原型(prototype)查找和无查找),但不幸的是,它对深入

javascript - AngularJS 服务未定义 : Unknown provider: $scopeProvider <- $scope

我已经开始学习AngularJS,但在将服务注入(inject)Controller时遇到了问题。我试图将ThreadFactory服务放入ThreadController中,但在调用它时遇到未定义的错误。任何建议都会很棒。我得到的错误是:未知提供者:$scopeProviderapp.jsangular.module('threadsApp',['ngRoute']);angular.module('threadsApp').config(function($routeProvider,$locationProvider){$routeProvider.when('/',{templ

javascript - 在 AngularJS 中使用来自不同 Controller 的 $scope 函数

这个问题在这里已经有了答案:CanoneAngularJScontrollercallanother?(14个答案)关闭9年前。我想在另一个Controller中共享一个Controller的$scope函数,在本例中为AngularUI对话框。特别是在下面的示例中,我希望$scope.scopeVar在PopupCtrl中可用。HereisaPlunkrResolvecodebasedonmlarcher'scommenthere主要.jsangular.module('MyApp',['ui.bootstrap']);varMainCtrl=['$scope','$dialog',

javascript - angularjs $scope.$apply() 给出此错误 : Error: [$rootScope:inprog]

我正在尝试更新属于$scope的页面上的一些文本。但我不断收到此错误:Error:[$rootScope:inprog][http://errors.angularjs.org/1.2.15/$rootScope/inprog?p0=%24apply][1]atError(native)athttps://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:6:450atm(https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:1

javascript - 如何将 $scope 传递给 angularjs 1.5 组件/指令

我正在尝试在Angular1.5中使用新的.component()方法。目前我发现关于如何使用它的信息很少。Angular文档也没有真正提到它。我正在尝试将作用域或对象从作用域传递到.component以在组件的模板部分中使用,但我可以传递的唯一两个参数是$element和$attrs。我尝试通过html中的属性传递对象,但我得到的只是对象名称的字符串。我尝试过将其设置为以这些方式表示为变量my-attr="item.myVal"my-attr="{item.myVal}"my-attr="{{item.myVal}}"每次我仍然得到字符串文字而不是变量的值。如何将其设置为作为变量处理

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