【问题标题】:cannot find OnInit in typescript during implementation实施期间在打字稿中找不到 OnInit
【发布时间】:2017-02-10 18:29:45
【问题描述】:

我正在处理一个带有 loginComponent 的示例项目,当我尝试添加 OnInit 时,我需要在我的类中实现 OnInit 我收到以下错误

[ts] 找不到 OnInit

这是我的代码

export class loginComponent implements OnInit{

 ngOnInit():all{

    }
}

如何解决这个问题

提前致谢

【问题讨论】:

  • 使用ngOnInit(): any
  • 我试过了,但还是报同样的错误
  • 问题中无需复制答案,我们也不会在此处使用 [已解决] 标题修正。谢谢!

标签: angular


【解决方案1】:
import { OnInit } from '@angular/core';

【讨论】:

    【解决方案2】:

    您需要从“@angular/core”导入它。此外,您不需要从此方法返回任何内容,因此您可以安全地跳过返回类型。

    import {OnInit} from '@angular/core';
    
    export class loginComponent implements OnInit {
        ngOnInit() {
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-10-13
      • 2016-12-13
      • 1970-01-01
      • 2022-08-12
      • 1970-01-01
      • 2020-05-02
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      相关资源
      最近更新 更多