2015-02-05 5 views
0

안녕하세요, 날짜를 빼는 간단한 함수를 만들었지 만 오류가 계속 발생합니다.날짜 빼기 오류 (보간 할 수 없음)

코드 JS :

 $scope.tosum = function(d1, d2) { 

     var d3 = new Date(d1.getTime() - d2.getTime()); 
     console.log(d3); 
     return d3; 
    }; 

콘솔 오류 :

Error: [$interpolate:interr] Can't interpolate: 
{{tosum(timesheet.startDate,timesheet.endDate)}} 
TypeError: undefined is not a function 

보기/html로 사이트 :이에 '잘못된 날짜'를 제공합니다 나는 또한 .getTime없이 시도

<tr data-ng-repeat="timesheet in timesheetsCtrl.timesheets | filter:searchText"> 
    <td>{{tosum(timesheet.startDate,timesheet.endDate)}}</td> 

콘솔

+0

'd1'과'd2'를 로그하면, 그것들은 올바르게 정의 된 날짜이고 다른 유형의 객체가 아닌 것이 확실합니까? – mgilson

+0

timesheet.startDate에 무엇이 들어 있습니까? –

+0

console.log ('d1 :'+ d1 + '- d2 :'+ d2); 출력 : D1 : 2015-02-02T23 : 00 : 00.000Z - D2 : 2015-02-04T15 : 16 : UI에 MongoDB를 – Stweet

답변

0

당신이 우리가 있습니까? 컨트롤러에요?

아니요, 그냥 함수의 이름을 쓰십시오. 그렇지 않으면 컨트롤러 이름의 접두사가 필요합니다.

+0

동일한 컨트롤러에서 this.tosum = function (d1, d2) {...로 변경되었습니다. .. {timesheetsCtrl.tosum (timesheet.startDate, timesheet.endDate)}} 하지만 여전히 같은 오류 – Stweet