【发布时间】:2016-10-14 06:49:36
【问题描述】:
我正在尝试在我的应用程序中计算员工的经验。我打算通过从“当前日期”中减去“careerStartedOn”来做到这一点。
这是我的控制器代码:
myApp.controller('getAllBenchersController', ['$scope', 'employeeTalentPoolServices', 'dataTable', '$window', '$timeout', function ($scope, employeeTalentPoolServices, dataTable, $window, $timeout) {
employeeTalentPoolServices.getAllBenchers().then(function (result) {
var mainData = result.data;
$scope.date = new Date();
$scope.blockEmployee = function (id) {
employeeTalentPoolServices.blockEmployee(id);
$scope.showhide = false;
}
});
employeeTalentPoolServices.getCustomerAccounts().then(function (result) {
$scope.accountData = result.data;
});
}]);
HTML:
<div class="widget-content table-container" ng-controller="getAllBenchersController">
<table ng-table="talentPoolList" show-filter="true" class="table table-striped table-bordered">
<tr ng-repeat="employee in data">
<td data-title="'Experience'" sortable="'Experience'" filter="{ 'account': 'text' }">
{{employee.careerStartedOn | date:myApp.dateFormat}}
</td>
</tr>
</table>
在 HTML 中,如果我调用 {{employee.careerStartedOn | date:myApp.dateFormat}},我会得到“careerStartedOn”日期,当我调用 {{date | date:myApp.dateFormat}} 时,我会得到当前日期。
我需要从当前 date 中减去 careerStartedOn 日期,然后将其显示在 <td> 中。我是个新手,找不到解决方案。
谁能帮我写代码来实现这个目标?
提前谢谢...
【问题讨论】:
-
你想展示什么?您可以为此使用
moment.js -
我想显示计算结果 (CurrentDate - CareerStartedOn 。差异应该是年/月数
-
@DanielShillcock - 它在您提到的帖子中使用 javascript。我想知道如何使用控制器在 AngularJS 中实现这一点。
-
@pro.mean - 我想显示计算的结果 (CurrentDate - CareerStartedOn 。差异应该是年/月。你能告诉我一个如何使用的例子吗? moment.js?我不知道在哪里做。在控制器中还是在 HTML 中?
标签: angularjs date controller