首页 > 解决方案 > 模块 './login/servcioprueba1.service"' 没有导出成员 'prueba'.ts(2305)

问题描述

我有 Angular 8 的服务文件

ng gs servicioprueba1

我按如下方式导入文件

见第 2 块

并在 Block 的这一行

从'./servcioprueba1.service'导入{prueba};我收到错误 << Module '"../extra/login/servcioprueba1.service"' has no export member 'prueba'.ts(2305) >>

有人知道,我怎么能解决这个错误

注意:在 angular 8 的其他项目中,代码工作正常

保护你

第 2 座

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from  '@angular/forms';
import { Router } from  '@angular/router';
import { Observable } from 'rxjs'; 
import { prueba } from './servcioprueba1.service';

@Component({
  selector: 'page-login',
  templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class PageLoginComponent implements OnInit {

constructor(private authService: prueba) { }

}

标签: angularservice

解决方案


在服务所属的模块中,确保将其列为提供者

// other imports
import { prueba } from '<path_to_prueba.service.ts>'; 

@NgModule({
    declarations: [<Name_Of_Module>],
    imports: [
        //...
    ],
    providers: [
        //other providers ...
        prueba,
    ],
})
export class <Name_Of_Module> {}

然后PageLoginComponent所属的模块也一样。


推荐阅读