本文介绍了未定义Angular-cli + primeng需求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用[email protected](webpack)和[email protected].

I'm using [email protected] (webpack) and [email protected].

在创建了一个新的angular-cli项目之后,我进行了一些更改以添加primeng:

After create a fresh angular-cli project i made a few changes to add primeng:

package.json上的1:

1 on package.json:

"primeng": "^1.0.0-beta.15"

2 on angular-cli.json:

2 on angular-cli.json:

"styles": [ "styles.css", "../node_modules/primeng/resources/themes/omega/theme.css", "../node_modules/font-awesome/css/font-awesome.min.css", "../node_modules/primeng/resources/primeng.min.css" ],
"scripts": [ "../node_modules/primeng/primeng.js" ]

app.module.ts上的3:

3 on app.module.ts:

@NgModule({ declarations: [ AppComponent ],
imports: [ BrowserModule, FormsModule, HttpModule, PanelModule ],
providers: [], bootstrap: [AppComponent] }) export class AppModule { }

问题:

任何将primeng添加到angular-cli的帮助...我们将很棒! :)

Any help to add primeng to angular-cli... will we great! :)

推荐答案

所以大约,您所拥有的一切看起来都很好.

So just about everything you have there looks good.

问题在于您正试图将primeng作为脚本标签包括在内(这适用于jQuery之类的全局库).但是由于primeng部署了模块,因此您可以简单地将其导入模块中,然后像这样将其提供给NgModule:

The issue lies in that you're attempting to include primeng as a script tag (which is for global libraries like jQuery). But since primeng deploys modules you can simply import it in your module and then supply that to your NgModule like this:

import { ButtonModule } from 'primeng/components/button/button';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    ButtonModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

然后您还希望从angular-cli.json中删除对primeng.js的引用

And then you'll also want to remove the reference to primeng.js from your angular-cli.json

这篇关于未定义Angular-cli + primeng需求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 10:35