首页 \ 问答 \ 当编辑内部指令时,另一个指令中的Angular Directive会停止更新(Angular Directive inside another Directive stops updating when inner directive is edited)

当编辑内部指令时,另一个指令中的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
更新时间:2023-11-10 09:11

最满意答案

在这种情况下, 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", which destructures the array x into its constituent elements, and assigns them to the variables on the left-hand side.

相关问答

更多
  • 在这种情况下, 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模块发送内容。 在Python模块中,您将使用argv处理发送的数据,然后将一些结果返回给Ruby代码。 有关更多信息,我建议查看另一个类似的StackOverflow问题 。 Here are a few ways you c ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)