Is it possible to pass an EJS variable to an Angular ng-repeat filter?

泪湿孤枕 提交于 2019-12-11 08:30:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!