Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Select created by指令将接收更新,但不会更新其他指令_Javascript_Angularjs_Angularjs Directive_Angularjs Scope - Fatal编程技术网

Javascript Select created by指令将接收更新,但不会更新其他指令

Javascript Select created by指令将接收更新,但不会更新其他指令,javascript,angularjs,angularjs-directive,angularjs-scope,Javascript,Angularjs,Angularjs Directive,Angularjs Scope,我有如下指示。当我在ng模型中更改绑定到它的作用域变量时,指令创建的将更新,但当我更改本身时,它不会更新作用域变量。我想我缺少在链接中注册$watch,但我不确定。。。谢谢你的帮助 template.html <div ng-repeat="searchField in searchFields"> <select-search-field label="{{searchField.label}}" field="$parent[searchField.field]"&

我有如下指示。当我在ng模型中更改绑定到它的作用域变量时,指令创建的
将更新,但当我更改
本身时,它不会更新作用域变量。我想我缺少在链接中注册$watch,但我不确定。。。谢谢你的帮助

template.html

<div ng-repeat="searchField in searchFields">
    <select-search-field label="{{searchField.label}}" field="$parent[searchField.field]"></select-search-field>
</div>
指令.js

.directive('selectSearchField',function() {
  function template() {
    return '<label>{{label}}</label><br>' + 
      '<select ng-model="field">' + 
      '<option value="">Any</option>' + 
      '<option value="fixed">Fixed</option>' + 
      '<option value="retractable">Retractable</option>' + 
      '</select>';
  }

  return {
    restrict: 'E',
    scope: {
      label: '@',
      field: '=',
      options: '='
    },
    template: template()
  };
});
.directive('selectSearchField',function(){
函数模板(){
返回“{label}}
”+ '' + “任何”+ “固定”+ “可伸缩”+ ''; } 返回{ 限制:'E', 范围:{ 标签:“@”, 字段:'=', 选项:'=' }, 模板:模板() }; });
编辑:以下是github上的文件:(参见public/js/controllers.js和public/js/directives.js中的内容


另外:实时查看:

看起来您正在使用{{label}}但正在更新字段显示标签,因此您不会在那里看到更新,因为标签从未更新过

此外,字段属性不需要任何$parent内容,它将作为隔离范围的一部分对其进行计算

我做了一把小提琴,你要找的就是它

您可以单击“获取标签”按钮来警告控制器看到的值,以便确保双向数据绑定设置正确

以下是相关部分:

// in markup in the scope of the controller
<select-search-field field="searchField.field">
</select-search-field>
// part of the template, make sure to display the item we are changing!
return '<label>{{field}}</label><br>' + 
//在控制器范围内的标记中
//作为模板的一部分,请确保显示我们正在更改的项目!
返回“{field}}
”+
编辑:更新新信息

哦,所以您试图在父gear属性上使用ng模型。这有点奇怪,因为您试图绕过隔离。如果您只是不隔离,您可以只继承范围变量。或者,您仍然将字段作为双向数据绑定传递,并且只在父级上使用模型,如下所示:

'<select ng-model="$parent[field]">' + 
”+
以下是更新的小提琴:


希望这有帮助!

感谢您的帮助。我已经对为什么使用$parent等添加了一些说明。再次感谢。很酷,我更新了上面的答案,如果您有任何其他问题,请告诉我。再次感谢您的帮助-我已尝试完全绕过指令,并将其直接写入ng repeat中…仍然使用$parent[searchField.field]…这是我的确切代码:。再次感谢您的帮助。此外,我不知道numericSearchField指令为什么有效,但其他指令(或内联模板绑定)除外不要…嗯,我很难弄清楚你想要我回答什么。如果你有一些问题,如果你能提出几个清晰的问题,我会很有帮助,这样我就可以直接回答。或者是一些小提琴来说明一些问题。
// in markup in the scope of the controller
<select-search-field field="searchField.field">
</select-search-field>
// part of the template, make sure to display the item we are changing!
return '<label>{{field}}</label><br>' + 
'<select ng-model="$parent[field]">' +