类型参数 static: boolean; 不可分配给 read?: any 类型的参数
Posted
技术标签:
【中文标题】类型参数 static: boolean; 不可分配给 read?: any 类型的参数【英文标题】:Argument of type static: boolean; is not assignable to parameter of type read?: any 类型参数 static: boolean; 不可分配给 read?: any 类型的参数 【发布时间】:2019-10-26 07:53:56 【问题描述】:在我新创建的 Angular 应用程序中,我正在尝试使用 mattlewis92 的 angular-calendar 创建他的日历。我已经复制了他的 github 上列出的所有步骤和代码:https://mattlewis92.github.io/angular-calendar/#/kitchen-sink 但我一直在第一行收到错误消息,即@ViewChild('modalContent', static: true ) modalContent: TemplateRef<any>;
,上面写着“类型的参数 static: boolean; 是不可分配的类型为 read?: any " 的参数。这是其余的代码供参考,但我认为这并不重要:
import Component, ChangeDetectionStrategy, ViewChild, TemplateRef from '@angular/core';
import startOfDay, endOfDay, subDays, addDays, endOfMonth, isSameDay, isSameMonth, addHours from 'date-fns';
import Subject from 'rxjs';
import NgbModal from '@ng-bootstrap/ng-bootstrap';
import CalendarEvent, CalendarEventAction, CalendarEventTimesChangedEvent, CalendarView from 'angular-calendar';
import * as _moment from 'moment';
import JQ_TOKEN from '../common/jQuery.service';
const moment = _moment;
const colors: any =
red:
primary: '#ad2121',
secondary: '#FAE3E3'
,
blue:
primary: '#1e90ff',
secondary: '#D1E8FF'
,
yellow:
primary: '#e3bc08',
secondary: '#FDF1BA'
;
@Component(
selector: 'vacation',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './vacation.component.html',
styleUrls: ['./vacation.component.css']
)
export class VacationComponent
@ViewChild('modalContent', static: true ) modalContent: TemplateRef<any>;
view: CalendarView = CalendarView.Month;
CalendarView = CalendarView;
viewDate: Date = new Date();
modalData:
action: string;
event: CalendarEvent;
;
actions: CalendarEventAction[] = [
label: '<i class="fa fa-fw fa-pencil"></i>',
onClick: ( event : event: CalendarEvent ): void =>
this.handleEvent('Edited', event);
,
label: '<i class="fa fa-fw fa-times"></i>',
onClick: ( event : event: CalendarEvent ): void =>
this.events = this.events.filter(iEvent => iEvent !== event);
this.handleEvent('Deleted', event);
];
refresh: Subject<any> = new Subject();
events: CalendarEvent[] = [
start: subDays(startOfDay(new Date()), 1),
end: addDays(new Date(), 1),
title: 'A 3 day event',
color: colors.red,
actions: this.actions,
allDay: true,
resizable:
beforeStart: true,
afterEnd: true
,
draggable: true
,
start: startOfDay(new Date()),
title: 'An event with no end date',
color: colors.yellow,
actions: this.actions
,
start: subDays(endOfMonth(new Date()), 3),
end: addDays(endOfMonth(new Date()), 3),
title: 'A long event that spans 2 months',
color: colors.blue,
allDay: true
,
start: addHours(startOfDay(new Date()), 2),
end: new Date(),
title: 'A draggable and resizable event',
color: colors.yellow,
actions: this.actions,
resizable:
beforeStart: true,
afterEnd: true
,
draggable: true
];
activeDayIsOpen: boolean = true;
constructor(private modal: NgbModal)
dayClicked( date, events : date: Date; events: CalendarEvent[] ): void
if (isSameMonth(date, this.viewDate))
this.viewDate = date;
if (
(isSameDay(this.viewDate, date) && this.activeDayIsOpen === true) ||
events.length === 0
)
this.activeDayIsOpen = false;
else
this.activeDayIsOpen = true;
eventTimesChanged(
event,
newStart,
newEnd
: CalendarEventTimesChangedEvent): void
this.events = this.events.map(iEvent =>
if (iEvent === event)
return
...event,
start: newStart,
end: newEnd
;
return iEvent;
);
this.handleEvent('Dropped or resized', event);
handleEvent(action: string, event: CalendarEvent): void
this.modalData = event, action ;
this.modal.open(this.modalContent, size: 'lg' );
addEvent(): void
this.events = [
...this.events,
title: 'New event',
start: startOfDay(new Date()),
end: endOfDay(new Date()),
color: colors.red,
draggable: true,
resizable:
beforeStart: true,
afterEnd: true
];
deleteEvent(eventToDelete: CalendarEvent)
this.events = this.events.filter(event => event !== eventToDelete);
setView(view: CalendarView)
this.view = view;
closeOpenMonthViewDay()
this.activeDayIsOpen = false;
任何帮助将不胜感激为什么会发生这种情况或我将如何解决它?
【问题讨论】:
这取决于你使用的是什么版本的angular,如果你使用的是angular 8那么这段代码就可以了,否则删除 static: true
@penleychan 哦!好的谢谢!它说它适用于 6+,所以我只是认为这都是标准的,所以修复了它!
【参考方案1】:
一旦你升级到新版本的 Angular。删除node_module
文件夹并运行npm install
【讨论】:
确保您删除了适当的node_modules
文件夹(您可能有多个级别的node_modules
,您必须删除您的Angular 应用程序的node_modules
(即坐在在您的angular.json
文件旁边)考虑您的package-lock.json
是否适用于其他开发人员。它将在重新运行npm install
时更新@)
没有解决问题。请给我正确的解决方案。【参考方案2】:
如果您使用的是 Angular 7 或更少, static: true
对您来说将是一个问题。
请在 package.json 文件 "@angular/core": "~9.0.6"
中检查该项目的 Angular 版本
如果版本高于 7 则可以,只需在该项目的控制台中输入 npm install
即可更新项目并解决项目
如果版本小于或等于 7,则必须从出现问题的行中删除 static: true
希望能解决你的问题
【讨论】:
为我工作...只需要按照您所说的删除它...已解决....谢谢....我的错误是 src/app/orders/orders.component 中的错误。 ts(62,30): 错误 TS2345: 类型参数 ' static: boolean; ' 不能分配给 ' read?: any; 类型的参数。 '。对象字面量只能指定已知属性,而 ' read?: any; 类型中不存在 'static' '。以上是关于类型参数 static: boolean; 不可分配给 read?: any 类型的参数的主要内容,如果未能解决你的问题,请参考以下文章
TopScoreDocCollector类型的方法create(int,int)不支持参数(int,boolean)
LayoutInflater 类型中的方法 inflate(int, ViewGroup, boolean) 不适用于参数 (int, int, boolean)
void' 不可分配给类型为 '(value: User[], index: number) => boolean' 的参数
无法从 static 上下文引用非 static 方法 ‘updateByPrimaryKey(T, boolean)‘