I have a directive for the mover list called smDualList. The directive has the following template (partial code):
<div>
<select class="select-list" multiple
ng-model="unassigned"
name="unAssignedList"
data-no-dirty-check
ng-options="unassignedItem.descrip for unassignedItem in unassignedItems | orderBy:'descrip' | filter: filterCriteria"></select>
</div>
This is my page markup:
<data-sm:duallist-directive ng-required="false" keep-pristine="true"
unassigned-items-title="'@String.Format(Labels.availableX, Labels.items)'"
unassigned-items="currentBenefit.unassignedItems"
assigned-items-title="'@String.Format(Labels.assignedX, Labels.items)'"
assigned-items="currentBenefit.assignedItems"
sortable="false"
filter-criteria="{'categoryId':selectedCategoryId}"
selected-item="currentBenefit.selectedItem">
</data-sm:duallist-directive>
with the following code for the directive.js file:
restrict: 'E',
templateUrl: 'app/templates/smDuallist',
require: ['^form'],
scope: {
assignedItems: '=assignedItems',
unassignedItems: '=unassignedItems',
assignedItemsTitle: '=',
unassignedItemsTitle: '=',
filterCriteria: '=',
sortable: '=sortable',
selectedItem: '=?',
keepPristine: '=?'
},
link: function (scope, element, attrs, ctrls) {
scope.form = ctrls[0];
if (!scope.keepPristine)
scope.keepPristine = false;
}
So, the problem is that I need to add a true parameter at the end of the filter-criteria expression, so it would read as
filter-criteria="{'myColumn': myScopeProperty}:true"
Unfortunately, when I try to put it exactly like this on the form I get an error.
angular.js:13920 [Error: [$parse:syntax] Syntax Error: Token ':' is an unexpected token at column 34 of the expression [{'categoryId':selectedCategoryId}:true] starting at [:true].] http://errors.angularjs.org/1.5.8/$parse/syntax?p0=%3A&p1=is%20an%20unexpec…20token&p2=34&p3=%7B'categoryId'%3AselectedCategoryId%7D%3Atrue&p4=%3Atrue at http://localhost:9753/SiriuswareControl/Scripts/angular.js:68:12 at AST.throwError (http://localhost:9753/SiriuswareControl/Scripts/angular.js:14555:11) at AST.ast (http://localhost:9753/SiriuswareControl/Scripts/angular.js:14308:12) at ASTCompiler.compile (http://localhost:9753/SiriuswareControl/Scripts/angular.js:14771:31) at Parser.parse (http://localhost:9753/SiriuswareControl/Scripts/angular.js:15700:29) at $parse (http://localhost:9753/SiriuswareControl/Scripts/angular.js:15865:39) at initializeBinding (http://localhost:9753/SiriuswareControl/Scripts/angular.js:9988:25) at forEach (http://localhost:9753/SiriuswareControl/Scripts/angular.js:329:18) at initializeDirectiveBindings (http://localhost:9753/SiriuswareControl/Scripts/angular.js:9947:7) at nodeLinkFn (http://localhost:9753/SiriuswareControl/Scripts/angular.js:9242:30)
May be there is a way to somehow add that true parameter in the directive JavaScript code instead?
That last parameter is from the following discussion: Angular filter exactly on object key
I can probably create a filter function, but how can I create it to be generic enough to know which property to use? Because I have several movers in my form and I don't want to create a function in the controller for each of them.