javascript - AngularJS - 在 HTML 中调用函数

标签 javascript angularjs

我在我的 custom.js 中创建了一个函数 getAge()。这个函数需要在我的 HTML 页面中调用。

所以我尝试的是这样的:-

<td>{{getAge(user.basicinformation[0].dateofbirth)}}</td>

我看不到任何结果。

如何在 HTML 中调用函数?

最佳答案

因此,为 getAge 创建一个过滤器。

app.filter("getAge", function(){
   return function(input){
      // Your logic
      return output; 
   }
});

然后在 HTML 中调用它:

<td>{{ user.basicinformation[0].dateofbirth | getAge }}</td>

关于javascript - AngularJS - 在 HTML 中调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23798387/

相关文章:

apache - 使用在单独的域上运行Flask api和Angularjs前端的Apache正确配置Angularjs和CORS

javascript - 在 PHP 中使用 Javascript 打开 Bootstrap 模式

javascript - 如何复制div类颜色

javascript - gmaps4rails v2 fitMapToBounds()

javascript - 更新范围的 Angular 方式是什么?

javascript - 如何获取 angularjs 中的文本框值?

javascript - 将 AngularJS $filter 与 ng-disabled 一起使用

javascript - 在 Dialogflow v2 中使用 Node.js Webhook 自定义快速回复

javascript - 使用 REST 检查是否存在,但返回 404

javascript - 在 AngularJS 中成功的 http 请求上创建 DOM 元素