btx
btx

Reputation: 2497

Integrate OnsenUI in Angular 4

I'm really struggling with integrating OnsenUI in my Angular 2 (version 4) App. The project was generated using the latest Angular CLI. It seems the OnsenUI docs are not up to date.

So if add

import {OnsenModule} from 'angular2-onsenui';
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
.
.
.
@NgModule({
imports: [
    OnsenModule,
    BrowserModule
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]

as it is described in the docs: https://onsen.io/v2/docs/guide/angular2/

I'm getting the following error:

Uncaught ReferenceError: ons is not defined
at Object../node_modules/angular2-onsenui/dist/src/ons/notification.js (notification.js:5)
at __webpack_require__ (bootstrap 43794b3…:54)
at Object../node_modules/angular2-onsenui/dist/src/angular2-onsenui.js (angular2-onsenui.js:16)
at __webpack_require__ (bootstrap 43794b3…:54)
at Object../src/app/app.module.ts (app.component.ts:12)
at __webpack_require__ (bootstrap 43794b3…:54)
at Object../src/main.ts (environment.ts:8)
at __webpack_require__ (bootstrap 43794b3…:54)
at Object.2 (main.ts:12)
at __webpack_require__ (bootstrap 43794b3…:54)
./node_modules/angular2-onsenui/dist/src/ons/notification.js @ 
notification.js:5
__webpack_require__ @ bootstrap 43794b3…:54
./node_modules/angular2-onsenui/dist/src/angular2-onsenui.js @     angular2-onsenui.js:16
__webpack_require__ @ bootstrap 43794b3…:54
./src/app/app.module.ts @ app.component.ts:12
__webpack_require__ @ bootstrap 43794b3…:54
./src/main.ts @ environment.ts:8
__webpack_require__ @ bootstrap 43794b3…:54
2 @ main.ts:12
__webpack_require__ @ bootstrap 43794b3…:54
webpackJsonpCallback @ bootstrap 43794b3…:25
(anonymous) @ main.bundle.js:1

I don't want to use the monaca template, this will not solve the problem.

Upvotes: 0

Views: 1035

Answers (2)

Michat
Michat

Reputation: 1

Exactly the same problem. But, install angular-cli dependency and update the .angular-cli.json didn't worked for me (At origin, my project was not generated by angular-cli). It seems they're working on Angular 4 support:

https://github.com/OnsenUI/OnsenUI/tree/angular4-support

Wait and see...

Upvotes: 0

btx
btx

Reputation: 2497

Finally got the solution: As long as OnsenUI does not support Angular 4, you need to add the following to .angular_cli.json:

 "styles": [
    "../node_modules/onsenui/css/onsen-css-components.css",
    "../node_modules/onsenui/css/onsenui.css"
  ],
  "scripts": [
    "../node_modules/onsenui/js/onsenui.js"
  ],

Upvotes: 1

Related Questions