是否可以将EJS变量传递给Angular ng-repeat过滤器?

时间:2022-08-23 23:53:33

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?

我有一个配置文件页面,可以使用<%= user.local.name%>以纯文本呈现用户名称 - 这将使用Mongoose查询数据库。有没有办法可以将该值传递给Angular ng-repeat过滤器?

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?

我知道'Bob'是正在渲染的值,因为我将它显示在页面的其他位置。是否与括号内的变量有关?

1 个解决方案

#1


2  

Wrap that value in quotes! (Else angular looks for $scope.Bob, rather than just 'Bob')

用引号包裹该值! (Else angular寻找$ scope.Bob,而不仅仅是'Bob')

<tr ng-repeat="x in users | filter:{'name':'<%= user.local.name %>'}:true">

#1


2  

Wrap that value in quotes! (Else angular looks for $scope.Bob, rather than just 'Bob')

用引号包裹该值! (Else angular寻找$ scope.Bob,而不仅仅是'Bob')

<tr ng-repeat="x in users | filter:{'name':'<%= user.local.name %>'}:true">