【问题标题】:Creating Filters Inside of Angular Directive在 Angular 指令中创建过滤器
【发布时间】:2015-02-10 02:40:08
【问题描述】:

我很好奇为什么这个角度过滤器可以在 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>

【问题讨论】:

    标签: angularjs angularjs-directive angular-filters


    【解决方案1】:

    accordion-group 指令有一个独立的范围。 使用点符号再试一次(在处理范围继承时很重要)

    例如,将 ng-model 更改为:

    ng-model="searchForm.input"
    

    你会发现它会起作用。

    请参考:

    AngularJS documentation on scopes

    Egghead video on the dot notation

    【讨论】:

      猜你喜欢
      • 2020-07-26
      • 1970-01-01
      • 2019-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多