Dostaję ten błąd Podane parametry nie pasują do żadnej sygnatury celu połączenia. kiedy próbuję to zrobić w moim pliku TypeScript w Angular2.
console.log(Date(this.field.sowing_date));
Jeśli wykonam to samo w Chrome Debugger, nie mam żadnego problemu.
Czy wiesz co to jest?
Ja używam:
„@ angular / core”: „^ 2.4.0” „@ angular / cli”: „^ 1.0.0-rc.4”, „@ angular / compiler-cli”: „^ 2.4.0”,
Odpowiedzi:
1 dla odpowiedzi № 1Nie możesz przekazać parametru do Date
kiedy nie używasz go jako konstruktora (bez new
):
W JavaScript:
Date(); // returns current date as string
Date("1/1/2017"); // ignores the parameter and returns the current date as string
TypeScript słusznie narzeka, ponieważ Date(param)
nie jest prawidłowym sposobem dzwonienia Date
.
Możesz użyć Date
w TypeScript jak:
let currentDateAsString : string = Date(); // if you want the current date string
let parsedDate: Date = new Date(this.field.sowing_date); // if you want to parse it.
Dokumentacja MDN na temat Date
co wyjaśnia sposoby Date
może być użyty: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date