我正在try 按照文档https://www.npmjs.com/package/ng-circle-progress来实现ng-circle-progress.

和.ts文件:

import { Component } from '@angular/core';
import { NgCircleProgressModule } from 'ng-circle-progress';

@Component({
  selector: 'app-side-navbar-card',
  standalone: true,
  imports: [
    NgCircleProgressModule.forRoot({
      radius: 60,
      space: -10,
      outerStrokeGradient: true,
      outerStrokeWidth: 10,
      outerStrokeColor: '#4882c2',
      outerStrokeGradientStopColor: '#53a9ff',
      innerStrokeColor: '#e7e8ea',
      innerStrokeWidth: 10,
      title: 'UI',
      animateTitle: false,
      animationDuration: 1000,
      showUnits: false,
      showBackground: false,
      clockwise: false,
      startFromZero: false,
      lazy: true,
    }),
  ],
  templateUrl: './side-navbar-card.component.html',
  styleUrl: './side-navbar-card.component.css',
})

导出类SideNavbarCardComponent{}

而这import

NgCircleProgressModule.forRoot({
      radius: 60,
      space: -10,
      outerStrokeGradient: true,
      outerStrokeWidth: 10,
      outerStrokeColor: '#4882c2',
      outerStrokeGradientStopColor: '#53a9ff',
      innerStrokeColor: '#e7e8ea',
      innerStrokeWidth: 10,
      title: 'UI',
      animateTitle: false,
      animationDuration: 1000,
      showUnits: false,
      showBackground: false,
      clockwise: false,
      startFromZero: false,
      lazy: true,
    }

导致错误的原因:

Component imports contains a ModuleWithProviders value, likely the result of a 'Module.forRoot()'-style call. These calls are not used to configure components and are not valid in standalone component imports - consider importing them in the application bootstrap instead.

所以我从工作中的StackBlitz复制并粘贴了 https://stackblitz.com/edit/stackblitz-starters-rkwa4c?file=src%2Fmain.ts个 :

import { Component, ViewChild, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { bootstrapApplication } from '@angular/platform-browser';
import {
  CircleProgressComponent,
  CircleProgressOptions,
  NgCircleProgressModule,
} from 'ng-circle-progress';

@Component({
  selector: 'app-side-navbar-card',
  standalone: true,
  imports: [CommonModule, NgCircleProgressModule],
  providers: [
    (
      NgCircleProgressModule.forRoot(
        {},
      ) as ModuleWithProviders<NgCircleProgressModule>
    ).providers!,
  ],
  template: `
    <circle-progress
      name="A"
      [options]="optionsA"
      [renderOnClick]="false"
      class="copy"
      (click)="copyOptions($event, optionsA)"
    ></circle-progress>
  `,
})
export class App {
  name = 'Angular';
  options = new CircleProgressOptions();
  /*
  ngCircleOptions = {
    percent: 85,
    radius: 60,
    showBackground: false,
    outerStrokeWidth: 10,
    innerStrokeWidth: 5,
    startFromZero: false,
    outerStrokeColor: null,
    showSubtitle: false,
    subtitleFormat: (percent: number): string => {
      if (percent < 25) {
        this.ngCircleOptions.outerStrokeColor = 'red';
      } else if (percent < 50) {
        this.ngCircleOptions.outerStrokeColor = 'yellow';
      } else if (percent < 75) {
        this.ngCircleOptions.outerStrokeColor = 'blue';
      } else {
        this.ngCircleOptions.outerStrokeColor = 'green';
      }
      return '';
    },
  };*/

  optionsA: CircleProgressOptions = {
    ...this.options,
    percent: 85,
    radius: 110,
    showBackground: false,
    outerStrokeWidth: 10,
    innerStrokeWidth: 5,
    subtitleFormat: false, // clear subtitleFormat coming from other options, because Angular does not assign if variable is undefined.
    startFromZero: false,
  };

  @ViewChild('circleProgress') circleProgress!: CircleProgressComponent;

  copyOptions = (event: any, options: any) => {
    this.options = Object.assign(
      {},
      this.circleProgress.defaultOptions,
      options,
    );
  };
}

bootstrapApplication(App);

但我得到了一个错误:

Module '"../side-navbar-card/side-navbar-card.component"' has no exported member 'SideNavbarCardComponent'. even though i have `export` keyword next to classes.

推荐答案

我们只需要使用importProvidersFrombootstrapApplication部分导入提供程序一次,如下所示!

bootstrapApplication(App, {
  providers: [
    importProvidersFrom(
      NgCircleProgressModule.forRoot({
        radius: 60,
        space: -10,
        outerStrokeGradient: true,
        outerStrokeWidth: 10,
        outerStrokeColor: '#4882c2',
        outerStrokeGradientStopColor: '#53a9ff',
        innerStrokeColor: '#e7e8ea',
        innerStrokeWidth: 10,
        title: 'UI',
        animateTitle: false,
        animationDuration: 1000,
        showUnits: false,
        showBackground: false,
        clockwise: false,
        startFromZero: false,
        lazy: true,
      })
    ),
  ],
});

Stackblitz Demo

没有必要完全复制粘贴Stackblitz,你得到第二个错误的原因是因为当你复制粘贴代码时,你得到的是export class App而不是export class SideNavbarCardComponent,我想!

Javascript相关问答推荐

如何修复内容安全策略指令脚本-SRC自身错误?

使用JavaScript重新排序行

仅针对RTK查询中的未经授权的错误取消maxRetries

Google maps API通过API返回ZERO_RESULTS,以获得方向请求,但适用于Google maps

在react JS中映射数组对象的嵌套数据

如何通过使用vanilla JS限制字体大小增加或减少两次来改变字体大小

rxjs插入延迟数据

当id匹配时对属性值求和并使用JavaScript返回结果

在css中放置所需 colored颜色 以填充图像的透明区域

Nextjs 13.4 Next-Auth 4.2登录(&Quot;凭据&,{});不工作

如何确保预订系统跨不同时区的日期时间处理一致?

如何修复使用axios运行TSC index.ts时出现的错误?

Socket.IO在刷新页面时执行函数两次

JAVASCRIPT SWITCH CASE语句:当表达式为';ALL';

我为什么要使用回调而不是等待?

Chrome上的印度时区名S有问题吗?

限制数组中每个元素的长度,

JavaScript -如何跳过某个字符(S)来打乱字符串中的字符

在Reaction Native中,ScrolltoIndex在结束时不一致地返回到索引0

观察子组件中的@Output事件emits 器?