【发布时间】:2017-08-26 03:57:00
【问题描述】:
我有一个组件使用另一个带有 ngIf 语句的组件。一旦 ngIf 评估为 true,我只想加载第二个组件。
编辑:发现一篇几乎可以满足我需要的文章: https://medium.com/@matanlurey/lazy-loading-with-angular-dart-14f58004f988。但是,在加载库之后,它会获取组件的整个视图。就我而言,我需要将其插入到父组件的 html 中的特定位置。
类似:
import '../other/edit_component.dart' deferred as otherEdit;
@Component(
selector: 'edit-component',
template: '<other-component *ngIf="canOther"></other-component>
<button type="button" (click)="go()"></button>',
directives: const [
otherEdit.OtherComponent
]
)
class EditComponent {
@Input()
bool canOther = false;
go() {
otherEdit.loadLibrary();
canOther = true;
}
}
【问题讨论】:
-
所以你实际上想要延迟加载组件而不是指令。你想要一个指令来触发延迟加载。
-
正确,一个组件。搞错了,要修改一下
标签: dart lazy-loading angular2-dart