4.1 依賴性注入
令牌 構建 依賴
Injector Provider Object 難。。
4.2 changeDetection
檢查變化的策略:默認:全局檢查,
改爲onpush策略,減少全局檢查的頻率,大應用可以以此提高性能
(changeDetection:ChangeDetectionStrategy.OnPush)
然後在constructor中申明ChangeDetectorRef,再調用它的markDetector方法
constructor(...,private cd:ChangeDetectorRef )
xx(){
...
this.cd,markForCheck();
}
4.3 指令
指令:組件是一種帶模板的指令
指令分爲結構型(Structural)指令和屬性型(Attribute)指令
Renderer2 和 ElementRef
Angular不提倡直接操作DOM,這是一個危險的行爲
對於DOM的操作應該通過Renderer2來進行,ElementRef可以理解爲指向DOM元素的引用
drag-drop 拖拽
Can't bind to 'app-draggable' since it isn't a known property of 'mat-list-item'.
1. If 'mat-list-item' is an Angular component and it has 'app-draggable' input, then verify that it is part of this module.
2. If 'mat-list-item' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
'priority-emergency':item.priority===1
}"
[ERROR ->][app-draggable]="true"
[draggedClass]="drag-start"
(click)="onItemClick()"
"): ng:///TaskModule/TaskItemComponent.html@7:2
--->莫名其妙 多保存幾次就好了
[app-draggable]="true"
[draggedClass]="'drag-start'" 不加''會認爲是成員變量,找不到就是undefined