angular2-notifications icon indicating copy to clipboard operation
angular2-notifications copied to clipboard

How to make it working in webpack?

Open xinzhang opened this issue 8 years ago • 5 comments

There is no example to include it with webpack (angular-cli) template.

I followed the toast notification documentation to add the SimpleNotificationComponent in the module Then in the component, I injected the notificationService to call it.

However, there is no issue in running webapack build but I am getting the below error. metadata_resolver.js:227Uncaught Error: Unexpected directive 'SimpleNotificationsComponent' imported by the module '....Module'

What could be the issue? Is there a better example to use it in a webpack template or angular-cli template?

xinzhang avatar Dec 12 '16 06:12 xinzhang

Hi, I am in the process of creating an application template using CLI and some of the libraries. For a simple example have a look at my new template repository. https://github.com/olakara/ng2-app-template I have added the angular2-notifications to the CLI based application.

olakara avatar Dec 12 '16 18:12 olakara

Hi, I get it working and here is what to do,

In the module, import {SimpleNotificationsModule, PushNotificationsModule} from 'angular2-notifications'; and add the modules into imports:[....]

In the component, include the tag in the component.html <simple-notifications [options]="options" (onCreate)="onCreate($event)" (onDestroy)="onDestroy($event)">

then in the component to add the below declaration import {NotificationsService, SimpleNotificationsComponent} from 'angular2-notifications'; and add the NotificationsService in the constructor, and show notification by calling this.notificationService.success("title", "...");

Thanks.

xinzhang avatar Dec 13 '16 05:12 xinzhang

It works on development mode, but when try to generate a distribution version using UglifyJsPlugin it triggers an error:

ERROR in app.c3b86f6b3725dad90c4b.js from UglifyJs
SyntaxError: Unexpected token: name (NotificationsService) [app.c3b86f6b3725dad90c4b.js:11,6]

ghost avatar Dec 16 '16 14:12 ghost

Pls check 112

notprathap avatar Dec 19 '16 17:12 notprathap

I follow @xinzhang solution and I found this almost 100% accurate to my project built with webpack. TY @xinzhang ! :+1:

egel avatar Jan 11 '17 08:01 egel