简体   繁体   English

从 Angular 库中实现组件的问题

[英]Problems Implementing a Component from an Angular Library

So im making my own angular library.所以我正在制作我自己的 angular 库。

I followed the steps listed here: https://angular.io/guide/creating-libraries我按照此处列出的步骤操作: https://angular.io/guide/creating-libraries

So i created the library and published it to npmjs.com.所以我创建了库并将其发布到 npmjs.com。

My issue is, whenever I tried making a new component inside the library, It seems like the intellisense recognizes that the component is there however when i try to run my angular application i get faced with this error:我的问题是,每当我尝试在库中创建一个新组件时,似乎智能感知识别该组件在那里但是当我尝试运行我的 angular 应用程序时,我遇到了这个错误:

ERROR in No NgModule metadata found for 'AppModule'.

Here is a snippet of the librarys module:这是库模块的片段:

import { NgModule } from '@angular/core';
import { SlEcommComponent } from './sl-ecomm.component';
import { SlCatalogComponent } from './sl-catalog/sl-catalog.component';



@NgModule({
  declarations: [SlEcommComponent, SlCatalogComponent],
  imports: [
  ],
  exports: [SlEcommComponent, SlCatalogComponent]
})
export class SlEcommModule { }

The component im trying to use is SlCatalogComponent.我尝试使用的组件是 SlCatalogComponent。 The other component, SlEcommComponent, seems to work but this is the component that was auto generated by the angular CLI.另一个组件 SlEcommComponent 似乎可以工作,但这是由 angular CLI 自动生成的组件。

So heres a snippet of the consuming projects appmodule:因此,这是消费项目 appmodule 的片段:

import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { CommonDataService } from './_services/common-data.service';
import { SignInComponent } from './sign-in/sign-in.component';
import { SlEcommModule } from 'sl-test';


@NgModule({
  declarations: [
    AppComponent,
    SignInComponent,
  ],
  imports: [
    SlEcommModule
  ],
  providers: [CommonDataService],
  bootstrap: [AppComponent]
})
export class AppModule { }

And finally on the signin components template, im using a component from the library i made like this:最后在登录组件模板上,我使用了我制作的库中的一个组件,如下所示:

<sl-catalog></sl-catalog>

Im not sure what else im missing since the default component in the library works, and mine does not.我不确定我还缺少什么,因为库中的默认组件有效,而我的没有。

--Edit-- - 编辑 -

So ive narrowed down the problem to my npm package not having the a certain folder included when its being published.所以我将问题缩小到我的 npm package 在发布时没有包含某个文件夹。

After adding the "files": ["lib"] to the package.json everything seems to be working ok except the intellisense here is screwed up:"files": ["lib"]添加到 package.json 后,一切似乎都正常,除了这里的智能感知被搞砸了:

在此处输入图像描述

What seemed to fix my issue is adding "files": ["./src/lib"] to my package.json似乎解决我的问题的方法是将"files": ["./src/lib"]添加到我的 package.json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM