我尝试使用UpgradeComponent在Angular 4应用程序中使用Angular 1库(ui-grid)。
我的步骤:
创建新指令:
import {
Directive, ElementRef, Injector, Input, OnInit, SimpleChanges, OnChanges,
DoCheck,
OnDestroy, Output, EventEmitter, Inject
} from '@angular/core';
import { UpgradeComponent } from '@angular/upgrade/static';
@Directive({selector: 'ui-grid'})
export class UiGridDirective extends UpgradeComponent implements OnInit, OnChanges, DoCheck,
OnDestroy {
@Input() data: {};
@Output() onUpdate: EventEmitter<{}>;
constructor(@Inject(ElementRef) elementRef: ElementRef, @Inject(Injector)
injector: Injector) {
super('ui-grid', elementRef, injector);
}
ngOnInit() { super.ngOnInit(); }
ngOnChanges(changes: SimpleChanges) { super.ngOnChanges(changes); }
ngDoCheck() { super.ngDoCheck(); }
ngOnDestroy() { super.ngOnDestroy(); }
}
将其添加到我的模块
declarations: [UiGridDirective],
尝试在我的index.html
中导入它<script src="https://cdn.rawgit.com/angular-ui/bower-ui-grid/master/ui-grid.min.js"/>
得到了这个错误:
在第3步之前:
ERROR Error: Uncaught (in promise): Error: StaticInjectorError[$injector]:
StaticInjectorError[$injector]:
NullInjectorError: No provider for $injector!
在第3步之后:
我知道如何在Angular 4应用程序中使用这个AngularJS库吗?