2016-09-15 75 views
1

我使用[email protected](webpack)和[email protected]Angular-cli + primeng需求未定義

創建一個新的角度,CLI項目後,我做了一些修改補充primeng:對角cli.json

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

2:

"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" ] 

1上的package.json

上app.module.ts 3:

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

問題:

Uncaught ReferenceError: require is not defined Unexpected value 'undefined' imported by the module 'AppModule'

任何有助於primeng極大增加角CLI ......將我們! :)

回答

8

因此只是約所有你在那裏看起來不錯。

問題在於您試圖將primeng作爲腳本標記(這適用於像jQuery這樣的全局庫)。但由於primeng部署的模塊,可以簡單地將其導入您的模塊中,然後提供,爲您的NgModule這樣的:

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

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

然後你還需要從您的角度,CLI刪除提及primeng.js .json

+1

非常感謝Brocco,你已經度過了我的一天! –