问题
I have a profile page that can render a user's name in plain text using <%= user.local.name %> - this queries the database using Mongoose. Is there a way I can pass that value to an Angular ng-repeat filter?
This works:
<tr ng-repeat="x in users | filter:{'name':'Bob'}:true">
But this does not work:
<tr ng-repeat="x in users | filter:{'name':<%= user.local.name %>}:true">
I know that 'Bob' is the value being rendered, because I display it elsewhere on the page. Does it have something to do with the variable being inside the brackets?
回答1:
Wrap that value in quotes! (Else angular looks for $scope.Bob
, rather than just 'Bob'
)
<tr ng-repeat="x in users | filter:{'name':'<%= user.local.name %>'}:true">
来源:https://stackoverflow.com/questions/30081967/is-it-possible-to-pass-an-ejs-variable-to-an-angular-ng-repeat-filter