当编辑内部指令时,另一个指令中的Angular Directive会停止更新(Angular Directive inside another Directive stops updating when inner directive is edited)
所以我在另一个指令中有一个指令。 这两个指令使用相同的属性,该属性使用服务共享,并且它们都有输入来编辑此属性。 outer指令使用“transclude”来显示内部指令。 编辑外部指令时,内部指令正确更新。 但是,在更新内部指令时,连接似乎会丢失。
这是代码:
var myApp = angular.module('myApp',[]); myApp.controller('MyCtrl', function($scope, dataService) { }); myApp.directive('dir1', function(dataService){ return { restrict: 'E', transclude:true, template: '<h3>Directive 1</h3><input type="text" ng-model="item"/><div ng-transclude></div>', link: function(scope, elem, attr) { scope.data = dataService; } }; }); myApp.directive('dir2', function(dataService){ return { restrict: 'E', template: '<h3>Directive 2</h3><input type="text" ng-model="item"/>', link: function(scope, elem, attr) { scope.data = dataService; } }; }); myApp.factory('dataService', [function(){ return { item: "" }; }]);
这是它的观点:
<div ng-controller="MyCtrl"> <dir1> <dir2> </dir2> </dir1> </div>
我做了一个JSFiddle来展示我的问题http://jsfiddle.net/stevescerri/19L24uL6/2/
感谢任何帮助,因为我找不到合适的工作,谢谢! :)
So I have a directive inside another directive. Both directives use the same property which is shared using a service and they both have an input to edit this property. The outer directive uses "transclude" to display the inner directive. When editing the outer directive, the inner directive updates correctly. But, when updating the inner directive, the connection seems to get lost.
Here is the code:
var myApp = angular.module('myApp',[]); myApp.controller('MyCtrl', function($scope, dataService) { }); myApp.directive('dir1', function(dataService){ return { restrict: 'E', transclude:true, template: '<h3>Directive 1</h3><input type="text" ng-model="item"/><div ng-transclude></div>', link: function(scope, elem, attr) { scope.data = dataService; } }; }); myApp.directive('dir2', function(dataService){ return { restrict: 'E', template: '<h3>Directive 2</h3><input type="text" ng-model="item"/>', link: function(scope, elem, attr) { scope.data = dataService; } }; }); myApp.factory('dataService', [function(){ return { item: "" }; }]);
And this is it's view:
<div ng-controller="MyCtrl"> <dir1> <dir2> </dir2> </dir1> </div>
I made a JSFiddle to show my problem http://jsfiddle.net/stevescerri/19L24uL6/2/
Any help would be appreciated as I cannot find a work around yet, thanks! :)
原文:https://stackoverflow.com/questions/35267925
最满意答案
在这种情况下,
define
x[0]
,x[1]
是变量名,x[2]
是表达式。 因此,在Python中,_, var, exp = x
是一个“解构赋值”,它将数组x
解构为其组成元素,并将它们分配给左侧的变量。In this case,
x[0]
isdefine
,x[1]
is the variable name, andx[2]
is the expression. So, in Python,_, var, exp = x
is a "destructuring assignment", which destructures the arrayx
into its constituent elements, and assigns them to the variables on the left-hand side.
相关问答
更多-
python中的lisp解释器(lisp interpreter in python)[2023-05-05]
在这种情况下, define x[0] , x[1]是变量名, x[2]是表达式。 因此,在Python中, _, var, exp = x是一个“解构赋值”,它将数组x解构为其组成元素,并将它们分配给左侧的变量。 In this case, x[0] is define, x[1] is the variable name, and x[2] is the expression. So, in Python, _, var, exp = x is a "destructuring assignment", ... -
是, 来自社区版本源代码https://github.com/JetBrains/intellij-community/blob/172.3652/python/python-community-configure/src/com/jetbrains/python/configuration/PyConfigurableInterpreterList.java#L79-L90 它将搜索所有可能的SDK家园,并添加检测到的SDK(如果存在)。 for (String sdkHome : SdkConfigur ...
-
输入python2.7并按Enter 如果你想知道路径 尝试which python2.7 ,例如: $which python2.7 /Users/haifzhan/.virt ...
-
从着名的perl hashbang技巧中获得灵感,我想出了这个: #!/bin/sh """": python2 -c "" 2>/dev/null && exec python2 $0 ${1+"$@"} python -c "" 2>/dev/null && exec python $0 ${1+"$@"} echo "Could not find a python interpreter." exit 1 """ print "hello python" Getting inspiration ...
-
这是终端的一个特征,而不是解释器。 Esc Esc被您的终端解释为Tab ,然后您的解释器会将其解释为完成请求。 That's a feature of the terminal, not the interpreter. EscEsc is interpreted as Tab by your terminal, which your interpreter then further interprets as a completion request.
-
PYTHONPATH 不是你想要的。 这是为了改变Python的“导入”寻找包和模块的地方。 您需要更改环境中的PATH变量,使其包含例如“....; c:\ python26; ....”而不是“....; c:\ python25; ....”。 单击开始>控制面板>系统>高级>环境变量。 选择“路径”。 编辑它。 单击确定足够的时间以离开那里。 PYTHONPATH is NOT what you are looking for. That is for varying where Python's ...
-
通常在天真的解释器中处理这种方式是使用垃圾收集器 (GC)并在GC堆中分配激活帧。 所以你从不明确地释放这些帧,你可以让GC在适用的时候释放它们。 在更复杂的实现中,您可以使用稍微不同的方法: 当创建闭包时,不要存储指向当前环境的指针。 相反,复制闭包使用的那些变量的值(它被称为lambda的自由变量 )。 并将封闭体更改为使用这些副本,而不是在环境中查找这些变量。 它被称为闭包转换 。 现在,您可以将您的环境视为普通堆栈,并在您退出示波器后立即释放激活帧。 你仍然需要一个GC来决定何时可以释放关闭 。 这 ...
-
好吧,它基本上说它找不到你刚刚安装的python解释器。 看起来你在Windows上,所以检查你的环境变量,特别是PATH和PYTHONPATH,它们可能仍然指向以前的2.6安装文件夹。 Well, it is basically saying that it cannot find your just installed python interpreter. It looks like you are on Windows so check your environment variables, par ...
-
试试这些: (documentation #'cons 'function) (documentation 'most-positive-fixnum 'variable) (describe #'cons) Slime还有一堆用于查看事物的快捷方式: slime-describe-symbol , slime-inspect (如果你有超级规范,那么slime-documentation-lookup )可能都很有用。 Try these: (documentation #'cons 'function ...
-
Python和Ruby解释器(Python and Ruby interpreter)[2022-04-25]
您可以通过以下几种方式完成此操作。 请注意,这些都没有特别高的性能: 它可能有点矫枉过正,但我之前使用套接字编程来建立Python和Ruby之间的客户端 - 服务器关系 。 至少这种方法感觉很酷。 您可以从公共文件中写入和读取。 但是你必须担心并发问题 。 反引号可用于向Python模块发送内容。 在Python模块中,您将使用argv处理发送的数据,然后将一些结果返回给Ruby代码。 有关更多信息,我建议查看另一个类似的StackOverflow问题 。 Here are a few ways you c ...