标签: angular-library

Angular 库无法导出类 - Angular6

我创建了一个新的 Angular 6 库。这个库有一个名为 User 的模型:

export class User {
    public id: string;
    public username: string;

    constructor(id: string,
                username: string) {
        this.id = id;
        this.username = username;
    }
}
Run Code Online (Sandbox Code Playgroud)

我在另一个角度应用程序中使用该库,一切正常。但是当我尝试使用模型时:

export class AppComponent {
  public user: User;

  constructor() {
    this.user = new User('1', 'my user');
  }
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Module not found: Error: Can't resolve 'my-lib/lib/models/user.model' in 'C:\my-app\src\app'
Run Code Online (Sandbox Code Playgroud)

智能感知找到了它,但我仍然收到此错误。

应用模块:

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    UserModule,
  ],
  bootstrap: [AppComponent]
})
Run Code Online (Sandbox Code Playgroud)

有人有想法吗?谢谢!

model angular-library angular6

2
推荐指数
1
解决办法
2136
查看次数

类不是 Angular 模块 - 仅在 IntelliJ/Webstorm 中导入本地构建的 Angular 库时

我正在尝试使用在单独的 Angular 应用程序中存在的库(项目)中实现的 Angular 模块。在 IntelliJ 中,我收到一个错误,Class MyModule is not an Angular module并且在我可以成功运行ng build此项目时,IntelliJ 中似乎无法识别所有库。更奇怪的是,我实际上有两个 Angular 库存在于另一个 Angular 应用程序中,我可以毫无问题地使用其他库中的模块。

我访问过其他类似的相关问题,class is not an Angular module但它们似乎并不相关。

intellij-idea angular angular-library

2
推荐指数
1
解决办法
2856
查看次数

将environment.ts传递给Angular库模块

我正在构建一个 Angular 库,它将公开服务和中间件,以便在导入其他 Angular 应用程序时执行身份验证。

在尝试将此模块拉入独立的Angular Library之前,它依赖于environment.ts应用程序中的文件(我只是像这样导入它import { environment } from '../../../environments/environment';:)。

如何将环境文件传递到现在将导入到我的 Angular 应用程序中的模块?

environment或者将文件作为 JSON 传递给我公开的每个服务和中间件是否更好?

angular-module angular angular-library

2
推荐指数
1
解决办法
3214
查看次数

在 ionic 项目中使用 angular 库时,必须从注入上下文中调用 inject()

我目前有一个项目,其中有一个 angular 工作区,我在其中创建了一个 angular web 应用程序。现在我还需要一个应用程序并创建了一个 angular ionic 应用程序。我想重用我现有的使用 AngularFireauth 和 AngularFirestore 的身份验证服务,所以我创建了一个库并提取了该服务。在 angular Web 应用程序中使用库中的服务时,一切正常。但是尝试在 ionic 应用程序的页面中注入服务时,我收到错误消息 inject() 必须从注入上下文中调用。当将服务从库移动到离子应用程序并从那里使用它时,它可以工作。

离子 v.5.0.5

角度 v.9.0.6

也许有人有想法。

谢谢你的帮助!

firebase ionic-framework angular angular-library

2
推荐指数
2
解决办法
3424
查看次数

Angular 库编译:错误:无法读取未定义的属性“then”

我有一个 Angular 11 工作区,其中包含多个项目(库)。最近我在一个库中添加了一个新组件,编译一切正常。在我的 public-api.ts 文件中公开新组件后,在编译我的库时(使用 ng build my-lib 命令),我收到了这一行无意义的错误:

错误:无法读取未定义的属性“then”

有人遇到过这个问题吗?请帮忙!

public-api.ts 最新更改:

export * from './lib/ray-autocomplete/ray-autocomplete.module';
export * from './lib/ray-autocomplete/ray-autocomplete.component';
Run Code Online (Sandbox Code Playgroud)

compilation angular angular-library

2
推荐指数
1
解决办法
2199
查看次数

组件库中的 Angular 7 包依赖项

我在 Angular 7 中创建了一个组件库,它将被移植到其他应用程序,并且这些应用程序将能够使用这些组件。

我遇到了一个问题,其中角度库安装在组件库中,但没有与组件库捆绑在一起以供在另一个应用程序中使用,并且我最终遇到了这样的错误......

Module not found: Error: Can't resolve '@angular/material' in
 'C:\Source\MappingServices\GIT\repos\SomeFolderStructure\node_mo
dules\@myComp\components\fesm5'


ERROR in ./node_modules/@myComp/components/fesm5/components.js
Run Code Online (Sandbox Code Playgroud)

我如何捆绑这样的库,以便它们与组件库一起使用,无需额外安装?

更新 Package.json 文件

{
"name": "@myComp/components",
"version": "0.0.1",
"whitelistedNonPeerDependencies": [
"agm","material", "ol"
],
"dependencies": {
"@angular/common": "^6.0.0-rc.0 || ^6.0.0",
"@angular/core": "^6.0.0-rc.0 || ^6.0.0",
"@agm/core": "^1.0.0-beta.5",
"ol": "^5.3.1"
},
"peerDependencies": {
"@angular/common": "^6.0.0-rc.0 || ^6.0.0",
"@angular/core": "^6.0.0-rc.0 || ^6.0.0",
"@agm/core": "^1.0.0-beta.5",
"ol": "^5.3.1"
},
"publishConfig": {
"registry": "http://someTFSdirectory"
}
}
Run Code Online (Sandbox Code Playgroud)

angular-components angular angular-library

0
推荐指数
1
解决办法
3529
查看次数

将库从 Angular 9 更新到 Angular 10 会产生错误 Symbol MatButton 在 .... 中声明,未从 @angular/material/button 导出

将 Angular 库从 Angular 9 更新到 Angular 10 后,我在构建库时收到以下错误。

ERROR: Symbol MatButton declared in ...........................  is not exported from @angular/material/button. 
Run Code Online (Sandbox Code Playgroud)

我无法理解原因,有人可以建议需要做什么吗?

谢谢,米纳克什

angular-material angular-library angular10

0
推荐指数
1
解决办法
5560
查看次数

Angular 10 在从不同工作区渲染组件时使用库时无法读取 null 的属性“bindingStartIndex”

我创建了一个 Angular-Library,它在我的 App-Workspace 之外。结果是我有两个不同的工作区。

我的第一种方法是构建我的库并将/dist文件夹与我的应用程序链接起来。这在 ng serve 上效果不佳,但无论如何我在渲染我的 Library-Component-Templates 时遇到了问题。

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'bindingStartIndex' of null
TypeError: Cannot read property 'bindingStartIndex' of null
[...]
Run Code Online (Sandbox Code Playgroud)

在做我的第一次研究时,我发现了这个 github 问题帖子

基本上给定的解决方案是在我的 tsconfig.json 中添加我的库public-api.ts中的路径,该路径可以导入到我的应用程序源中。像这样:

    "paths": {
    "@app/*": ["src/app/*"],
      "@core": ["src/app/@core"],
    "@core/*": ["src/app/@core/*"],
    "@shared": ["src/app/@shared"],
    "@shared/*": ["src/app/@shared/*"],
      "@env/*": ["src/environments/*"],
      "@myLibrary/*": ["../myLibrary/projects/myLibrary/src/public-api"]
  }
Run Code Online (Sandbox Code Playgroud)

不知何故,我在渲染模板时仍然遇到同样的问题。

因此,我的最后一种方法只是直接从我的 app.module.ts 导入我的 lib-Component

import { TestComponent } from '../../../../myLibrary/projects/myLibrary/src/lib/components/testComponent/test.component';
   @NgModule({
     imports: [
       FlexLayoutModule,
       CelNgZuiModule,
       CommonModule
   ],
   declarations: [FactoryModelComponent, TestComponent,]
   }) …
Run Code Online (Sandbox Code Playgroud)

typescript angular-module angular angular-library angular-ivy

0
推荐指数
1
解决办法
1908
查看次数