1

Using angular 1.6.4 I'm unable to use a filter on an ng-repeat across an adjacent component. In the example I've created a component for the dynamic listing of data (ng-repeat) and then a separate component for the search input. I can't figure out how to pass the data from the search component to the keyfeed component.

app.js

app.component('keyfeed', {
  bindings: { 
    search: '='
  },
  template: `
    <ul>
     <li ng-repeat="record in records | filter:search">{{ record }}</li>
    </ul>
  `,
  controller: function($scope) {
    $scope.records = [
      "Alfreds Futterkiste",
      "Berglunds snabbköp",
      "Centro comercial Moctezuma",
      "Ernst Handel",
    ];
  }
});

app.component('search', {
  bindings: { 
    search: '='
  },
  template: `
    <input type="search" search="$ctrl.search" ng-model="search">
  `,
  controller: function() {
  }
});

index.html

<search search="search"></search>
<keyfeed search="search"></keyfeed>

Plunker: view

1 Answer 1

1

You're missing the $ctrl you need to perform the actual bindings in the templates.

<li ng-repeat="record in records | filter:$ctrl.search">{{ record }}</li>

<input type="search" ng-model="$ctrl.search">

See the updated plnkr

Sign up to request clarification or add additional context in comments.

1 Comment

Ahh, so close. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.