[英]Pass angularjs variable to nodejs function from view
Is it possible to pass angularjs variable to a nodejs function from view like below 是否可以从如下所示的视图将angularjs变量传递给nodejs函数
// View
<div ng-repeat="user in users">
<img src="<%getUserImage(user)%>">
</div>
// Server
app.locals.getUserImage = function (user) {
if (user.url) { return user.url; };
return "/images/no-user.png";
}
I have the following error: Cannot read property 'url' of undefined 我遇到以下错误:无法读取未定义的属性“ url”
Can anyone help please ? 有人可以帮忙吗?
Thank you 谢谢
Why don't you perform this operation in the view instead of having to call the server function? 为什么不在视图中执行此操作,而不必调用服务器功能呢?
Just like this 像这样
<img ng-src="{{ user.url || '/images/no-user.png' }}"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.