在Angular Directive中创建过滤器

时间:2014-12-11 14:58:40

标签: angularjs angularjs-directive angular-filters

我很好奇为什么这个角度过滤器会在Angular指令之外工作,而不是在内部。有人可以提供解释吗?

例如,在下面的Plunkr中,我添加了一个搜索过滤器,它将在Bootstrap Angular UI手风琴之外工作,但是当删除并添加到内部时,它不起作用?

http://plnkr.co/edit/GdFvay?p=preview

 <div class="col-sm-4">
      <input type="text" ng-model="searchText" class="form-control" placeholder="Search All"> 
      <div>
        <accordion close-others="oneAtATime">
          <accordion-group >
            <accordion-heading>
              Search
            </accordion-heading>
            <input type="text" ng-model="searchText" class="form-control" placeholder="Search All"> 
          </accordion-group>
        </accordion>

1 个答案:

答案 0 :(得分:0)

手风琴组指令具有独立的范围。 使用点表示法再次尝试(在处理范围继承时很重要)

例如,将ng-model更改为:

ng-model="searchForm.input"

你会发现它会起作用。

请参阅:

AngularJS documentation on scopes

Egghead video on the dot notation