Webpack.ProvidePlugin angular

I am trying to use an angular NG6 starter. almost every js file is written in its source code import angular from angular . So I try this:

  new webpack.ProvidePlugin({ // $: "jquery", // jQuery: "jquery", // "window.jQuery": "jquery", 'angular': 'angular', }), 

But that will not work. I do not know why and how to solve this problem.

+5
source share
2 answers

Here's the solution to the first error message in your screenshot “angular.module is not a function”: Angular 1 does not work with webpack without a pad (see https://github.com/webpack/webpack/issues/2049 ). Try this webpack bootloader configuration:

 module: { loaders: [ /* * Necessary to be able to use angular 1 with webpack as explained in https://github.com/webpack/webpack/issues/2049 */ { test: require.resolve('angular'), loader: 'exports?window.angular' }, ] }, plugins: [ new webpack.ProvidePlugin({ 'angular': 'angular', }), ], 

This should initialize the Angular object properly, and not by default, to set it to an empty object (which does not have a property called module).

0
source

U need to use sth like this: var app = angular.module ('RequiredName', ['ui.router', 'ui.bootstrap']);

and use it in the application file and call your application module, as in parts of the project, and you are going to use any function or method implemented in the app.js file in app.factory or app.controller or ...

-1
source

All Articles