I am looking for a way to pass a filtered array to a directive:
I tried the following:
<my-directive model="myArray | filter:{myProperty: 'some value' }" />
but that will not work. I think that means what should be used with ng-repeat, because here I just pass a function instead of a filtered array.
Is there any way to do this other than creating a filtered copy of my array?
EDIT
Here is the full code:
<request-service type="editing" jobs="vm.selectedMaterial.jobs | filter:{service.code: 'ED'}"></request-service>
<request-service type="translation" jobs="vm.selectedMaterial.jobs | filter:{service.code: 'TR'}"></request-service>
and directive:
(function () {
'use strict';
var directiveId = 'requestService';
angular.module('comp.domain.directives').directive(directiveId, [directiveFunc]);
function directiveFunc(dependency) {
return {
restrict: 'E',
templateUrl: 'app/dm/views/templates/requestService.html',
scope: {
type: '@',
jobs: '='
},
link: function (scope, element, attrs) {
}
};
}
})();
while I get the error "Converting a circular structure to JSON"
EDIT 2
The following suggested solution, I did this:
$scope.filterJob = function (type) {
if ($scope.vm.selectedMaterial) {
return $scope.vm.selectedMaterial.jobs.filter(function (job) { return job.service.code === type; });
};
}
and in view:
<request-service type="ED" jobs="filterJob('ED')"></request-service>
But it still gives me the same error.
source
share