I have the following simplified plunker to demonstrate my issue:
html:
<my-directive ng-repeat="question in questions | filter:{show:true}" data-question="question"> </my-directive>
directive:
app.controller('MainCtrl', function($scope) {
$scope.questions = [
{qid:'1', show: true, text:'what is?'},
{qid:'2', show: false, text:'who is?'},
{qid:'3', show: true, text:'where is?'}
];
});
app.directive('myDirective', function() {
return {
link: function(scope){
scope.getShow = function(){
// some logic to determine show
// for simlicity , always return true so all questiosn show
return true;
};
},
restrict: "E",
scope: {
question: "="
},
template: '<h1>{{question.text}}</h1>'
};
});
Currently, the filter works based on the 'show' value that comes from the raw data model. but i am trying to clean it from raw data and make it work based on the getShow() logic that is defined at the question's scope level.
Generally, I cannot figure out a way to filter based on fields or functions on the scope, rather than on the data model, and could not find an example of how this could be done.