使用Angular UpgradeComponent

时间:2017-08-17 12:49:22

标签: angular ng-upgrade

我尝试使用UpgradeComponent在Angular 4应用程序中使用Angular 1库(ui-grid)。

我的步骤:

  1. 创建新指令:

    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(); }
    }
    
  2. 将其添加到我的模块

     declarations: [UiGridDirective],
    
  3. 尝试在我的index.html

    中导入它
    <script src="https://cdn.rawgit.com/angular-ui/bower-ui-grid/master/ui-grid.min.js"/>
    
  4. 得到了这个错误:

  5. 在第3步之前:

    ERROR Error: Uncaught (in promise): Error: StaticInjectorError[$injector]: 
      StaticInjectorError[$injector]: 
        NullInjectorError: No provider for $injector!
    

    在第3步之后:

    enter image description here

    我知道如何在Angular 4应用程序中使用这个AngularJS库吗?

0 个答案:

没有答案