模块在角度模块中没有导出成员错误

2024-03-03

我想创建一个功能模块来处理上传的前端。

上传组件.html没有错误。

<input
  type="file"
  #file
  style="display: none"
  (change)="onFilesAdded()"
  multiple
/>

<button mat-raised-button (click)="openUploadDialog()">Upload</button>

上传组件.ts2 个错误 - 导入上传和对话框组件

import { Component } from '@angular/core'
import { MatDialog } from '@angular/material'
import { DialogComponent } from './dialog/dialog.component'
import { UploadService } from './upload.service'

@Component({
  selector: 'app-upload',
  templateUrl: './upload.component.html',
  styleUrls: ['./upload.component.css'],
})
class UploadComponent {
  constructor(public dialog: MatDialog, public uploadService: UploadService) {}

  public openUploadDialog() {
    let dialogRef = this.dialog.open(DialogComponent, {
      width: '50%',
      height: '50%',
    })
  }
}

上传模块.ts3个错误,导入DialogComponent、上传服务、上传组件

import { NgModule } from '@angular/core'
import { CommonModule } from '@angular/common'
import { UploadComponent } from './upload.component'
import {
  MatButtonModule,
  MatDialogModule,
  MatListModule,
  MatProgressBarModule,
} from '@angular/material'
import { DialogComponent } from './dialog/dialog.component'
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { FlexLayoutModule } from '@angular/flex-layout'
import { UploadService } from './upload.service'
import { HttpClientModule } from '@angular/common/http'
import { from } from 'rxjs';

@NgModule({
  imports: [
    CommonModule,
    MatButtonModule,
    MatDialogModule,
    MatListModule,
    FlexLayoutModule,
    HttpClientModule,
    BrowserAnimationsModule,
    MatProgressBarModule,
  ],
  declarations: [UploadComponent, DialogComponent],
  exports: [UploadComponent],
  entryComponents: [DialogComponent], // Add the DialogComponent as entry component
  providers: [UploadService],
})
export class UploadModule {}  

上传服务.ts没有错误

import { Injectable } from '@angular/core'
import {
  HttpClient,
  HttpRequest,
  HttpEventType,
  HttpResponse,
} from '@angular/common/http'
import { Subject } from 'rxjs/Subject'
import { Observable } from 'rxjs/Observable'

const url = 'http://localhost:8000/upload'

@Injectable()
class UploadService {
  constructor(private http: HttpClient) {}

  public upload(files: Set<File>):
  { [key: string]: { progress: Observable<number> } } {

  // this will be the our resulting map
  const status: { [key: string]: { progress: Observable<number> } } = {};

  files.forEach(file => {
    // create a new multipart-form for every file
    const formData: FormData = new FormData();
    formData.append('file', file, file.name);

    // create a http-post request and pass the form
    // tell it to report the upload progress
    const req = new HttpRequest('POST', url, formData, {
      reportProgress: true
    });

    // create a new progress-subject for every file
    const progress = new Subject<number>();

    // send the http-request and subscribe for progress-updates
    this.http.request(req).subscribe(event => {
      if (event.type === HttpEventType.UploadProgress) {

        // calculate the progress percentage
        const percentDone = Math.round(100 * event.loaded / event.total);

        // pass the percentage into the progress-stream
        progress.next(percentDone);
      } else if (event instanceof HttpResponse) {

        // Close the progress-stream if we get an answer form the API
        // The upload is complete
        progress.complete();
      }
    });

    // Save every progress-observable in a map of all observables
    status[file.name] = {
      progress: progress.asObservable()
    };
  });

  // return the map of progress.observables
  return status;
}}

应用程序模块.ts导入上传组件时出错

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { NavbarComponent } from './navbar/navbar.component';
import { WelcomeComponent } from './welcome/welcome.component';
import { PagenotfoundComponent } from './pagenotfound/pagenotfound.component';
import { NavbarService } from './navbar/navbar.service';
import { UploadComponent } from './upload/upload.component';

@NgModule({
  declarations: [
    AppComponent,
    NavbarComponent,
    WelcomeComponent,
    PagenotfoundComponent,
    UploadComponent

  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [NavbarService],
  bootstrap: [AppComponent]
})
export class AppModule { }

我的 DialogComponent、UploadService 和 UploadComponent 出现错误“模块没有导出成员”。

我保留了对话框组件的代码,因为它很长,并且我认为问题的原因和上传组件是相同的。

非常困难 - 非常感谢帮助!


你的课程应该是exported使用export关键词。例如:

export class UploadComponent {
   ...
}

需要这样做是为了UploadService以及。否则该模块将无法导入它。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

模块在角度模块中没有导出成员错误 的相关文章

随机推荐

  • 子功能在 HTA 中不起作用

    我不知道为什么 但我的子功能不起作用 我以为我已经遵循了它应该如何工作 但它只会导致一个错误 声称我的函数未定义
  • 如何反转字符串中两个单词的顺序?

    我有一个像这样的字符串 a Mike Tree 我想将其反转为 Tree Mike 有什么功能可以做到这一点吗 将绳子分成两根绳子 翻转它们 然后重新连接它们 或者 使用正则表达式 a s 2 1 g
  • r 中的动态变量命名

    structure list Metrics structure c 1L 2L 3L 4L 5L 6L 1L 2L 3L 4L 5L 6L 1L 2L 3L 4L 5L 6L 1L 2L 3L 4L 5L 6L Label c LINES
  • 在未越狱的 iOS 设备上启用/禁用 Wifi

    我的内部应用程序需要这个 我想在 ios 设备上切换 wifi 任何框架都可用 我尝试了以下代码 但它没有为我提供任何帮助 这不会改变我的 wifi 设置 Class BluetoothManager objc getClass Bluet
  • 更改index.html nginx kubernetes部署

    我有这样的部署 我能够在我的一个 Pod 上编辑索引页面 但如何将其提交到部署映像 因此 当我扩展应用程序时 所有新的 Pod 都将具有相同的图像并编辑了索引 这对我有用 apiVersion v1 kind Pod metadata na
  • 使用 Id 以外的属性查询 DocumentDB

    我想查询 DocumentDB 数据库中的文档 我想使用 LINQ 处理 DocumentDB 查询并想要查询 facebookUsername 字段 如果我使用下面的代码来查询标准 Id 字段 它工作正常 但是当我尝试使用 faceboo
  • PHP 中是否可以声明静态方法和非静态方法?

    我可以将对象中的方法声明为静态方法和非静态方法 并且与调用静态方法的名称相同吗 我想创建一个具有静态方法 send 和调用静态函数的非静态方法的类 例如 class test private text public static funct
  • 如何使用callkit获取来电号码

    如何使用 Call Kit 框架以编程方式获取来电电话号码 我尝试使用 cxcallobserver 类 但没有用 任何建议最有帮助 使用 CallKit 的呼叫阻止和识别功能 iOS 10 中的新增功能 时 要阻止或识别的电话号码会在来电
  • 不在异步方法中等待任务的注意事项

    我正在开发一个 Web API 项目 该项目使用 Azure 的托管缓存服务将数据库结果缓存在内存中 以缩短响应时间并减少数据库的重复流量 当尝试将新项目放入缓存时 有时会抛出特定于缓存的异常 代码为DataCacheErrorCode R
  • 如何使用 Paramiko 运行 sudo? (Python)

    我尝试过的 invoke shell then channel send su然后发送密码导致不是root invoke shell 进而channel exec command导致 通道已关闭 错误 transport open sess
  • python * 运算符的正确名称?

    操作员的正确名称是什么 as in function args 解压 解压 还有别的吗 在 Ruby 和 Perl 6 中 这被称为 splat 我认为大多数人 如果你这么称呼的话 那些社区会明白你的意思 The Python教程 docs
  • SQL Server 2000 - 调试死锁

    我正在寻找有关如何调试和解决 SQL Server 2000 数据库中的死锁问题的建议 有人建议我使用跟踪标志 1024 和 3605 我发现它们可以提供以下信息 1024 此跟踪标志返回参与死锁的锁的类型以及受影响的当前命令 3605 此
  • 如何让背景图像跨越网格布局

    我有一个网格布局 假设第一行有 2 行 2 列 第二行有 3 列 它们之间的网格间隙为 10px 给每个网格一个背景图像是没有问题的 但是 如果我希望它们都具有相同的背景图像 该背景图像从左上角网格开始并继续 跨越直到右下角网格 所有网格上
  • 递归Kaatsuba 乘法不起作用?

    我正在尝试实施唐叶乘法 https en wikipedia org wiki Karatsuba algorithm通过递归调用 下面的代码应该可以工作 但我一直得到错误的答案 有什么想法吗 public static long kara
  • Java RandomString类[重复]

    这个问题在这里已经有答案了 可能的重复 HangMan RandomString 类 https stackoverflow com questions 13818297 hangman randomstring class 以下是方向 创
  • 将 UITableView 添加到现有 ViewController

    我正在尝试添加一个UITableView到现有的UIViewController以编程方式 My run h文件有这个 interface runTests UIViewController
  • 将 process.env.NODE_ENV 与 String 进行比较

    为什么当我比较这两个时我得到false const production process env NODE ENV production 即使当我设置process env NODE ENV到生产我仍然得到false value Why E
  • 获取python项目使用的所有模块/包

    我有一个 python GUI 应用程序 现在我需要知道应用程序链接到的所有库 这样我就可以检查所有库的许可证兼容性 我尝试过使用 strace 但 strace 似乎会报告所有包 即使应用程序未使用它们 而且 我尝试了 python Mo
  • 如何更改 mysql 表列默认值?

    我有一个带有 type 列的表timestamp默认值current timestamp并更新至current timestamp每次更新时 我想删除此列上的 更新时 功能 怎样写alter语句呢 我尝试了以下方法 ALTER TABLE
  • 模块在角度模块中没有导出成员错误

    我想创建一个功能模块来处理上传的前端 上传组件 html没有错误