Javascript 是否可以将value/ng模型从一个指令模板发送到另一个指令模板?(AngularJS)

Javascript 是否可以将value/ng模型从一个指令模板发送到另一个指令模板?(AngularJS),javascript,html,angularjs,templates,directive,Javascript,Html,Angularjs,Templates,Directive,让我们想想这里最简单的例子 如何将指令a模板中输入的文本值作为筛选器发送给指令B模板中作为ng repeat存在的列表?第一种方法-依赖于主机控制器的作用域 html js 第二种方法-指令参数 html js 你不能把它存储在你的控制器/范围内吗?A和B是兄弟姐妹还是B的父母?A和B是兄弟姐妹,如果他们是父母,那就不同了。感谢快速详细的回答=非常感谢!您是否碰巧知道,当我向它添加ng if时,它为什么停止工作?请改用ng show:。为什么? <first-directive>&l

让我们想想这里最简单的例子

如何将指令a模板中输入的文本值作为筛选器发送给指令B模板中作为ng repeat存在的列表?

第一种方法-依赖于主机控制器的作用域 html

js

第二种方法-指令参数 html

js


你不能把它存储在你的控制器/范围内吗?A和B是兄弟姐妹还是B的父母?A和B是兄弟姐妹,如果他们是父母,那就不同了。感谢快速详细的回答=非常感谢!您是否碰巧知道,当我向它添加ng if时,它为什么停止工作?请改用ng show:。为什么?
<first-directive></first-directive>
<second-directive></second-directive>
app.controller('myCtrl',function($scope, $location, $timeout) {

    $scope.items=['a ab', 'asd', 'www', '123'];
  }
);

app.directive('firstDirective', function() {
   return {
      restrict: 'EA',
      scope: false,
      template: '<div><input ng-model="input"></div>'
    };
});


app.directive('secondDirective', function() {
   return {
      restrict: 'EA',
      scope: false,
      template: '<div ng-repeat="item in items | filter:input">{{ item }}</div>'
    };
});
<first-directive filter-string="filterString"></first-directive>
<second-directive filter-string="filterString" items="items"></second-directive>
app.controller('myCtrl',function($scope, $location, $timeout) {
    $scope.items=['a ab', 'asd', 'www', '123'];
    $scope.filterString = '';
  }
);

app.directive('firstDirective', function() {
   return {
      restrict: 'EA',
      scope: { filterString:"=" },
      template: '<div><input ng-model="filterString"></div>'
    };
});


app.directive('secondDirective', function() {
   return {
      restrict: 'EA',
      scope: { filterString:"=",
      items:"="},
      template: '<div ng-repeat="item in items | filter:filterString">{{ item }}</div>'
    };
});