首页 文章

在stackblitz上找不到@ angular / common / http

提问于
浏览
1

我尝试在Stackblitz上创建一个新的服务文件,由于某种原因我收到一条错误消息:无法找到模块'@ angular / common / http'

与'rxjs / Observable'相同;知道为什么吗?它现在使用Angular 6 .

我在npm包下有@ angular / http

谢谢 .

1 回答

  • 4

    您需要将 @angular/http 包添加到依赖项 .
    enter image description here

    然后在你的主模块中:

    import { HttpClientModule } from '@angular/common/http';
    
    @NgModule({
      imports: [ ..., HttpClientModule],
      ...
    })
    

    它是rxjs 6,简化了导入:

    import { Observable } from 'rxjs'
    

相关问题