我有一个名为mock-values.ts
的文件,它只有:
export const TIMES: Time[] = [
{ i: '8:00', v: '8' }, { i: '8:30', v: '8:30' },
{ i: '9:00', v: '9' }, { i: '9:30', v: '9:30' },
{ i: '10:00', v: '10' }, { i: '10:30', v: '10:30' },
{ i: '11:00', v: '11' }
];
export const MINUTES: Minute[] = [
{ half_hour: '30' },
{ half_hour: '60' },
{ half_hour: '90' }
];
运行ng服务时,遇到此错误消息ERROR in src/app/meeting-form/mock-values.ts(1,21): error TS2304: Cannot find name 'Time'.
src/app/meeting-form/mock-values.ts(13,23): error TS2304: Cannot find name 'Minute'.
这是我在form.component.ts
import { TIMES, MINUTES } from './mock-values';
times = TIMES;
minutes = MINUTES;
大约一分钟后,它成功编译,因为最终找到了它。有什么办法告诉Angular放松一下或使编译器的过程更容易吗?
答案 0 :(得分:1)
类似“时间”和“分钟”的外观不是预定义的类型。请尝试如下更改代码:
export const TIMES = [
{ i: '8:00', v: '8' }, { i: '8:30', v: '8:30' },
{ i: '9:00', v: '9' }, { i: '9:30', v: '9:30' },
{ i: '10:00', v: '10' }, { i: '10:30', v: '10:30' },
{ i: '11:00', v: '11' }
];
export const MINUTES = [
{ half_hour: '30' },
{ half_hour: '60' },
{ half_hour: '90' }
];