Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import * as angular from 'angular' inside app.module.ts file

I have upgrade angular1 app to bootstrap with angular2 (upgrade option), but after importing angular with systemJS config:

map: {... 'angular': 'npm:angular/angular.js' ... }

The browser send error:

systemjs.import error: Error: (SystemJS) angular.module is not a function
    TypeError: angular.module is not a function
        at execute (http://msoqa05.devlab.ad:8088/home/bl/app.module.js:88:21)
        at ZoneDelegate.invoke (https://unpkg.com/[email protected]?main=browser:242:26)
        at Zone.run (https://unpkg.com/[email protected]?main=browser:113:43)
        at https://unpkg.com/[email protected]?main=browser:520:57
        at ZoneDelegate.invokeTask (https://unpkg.com/[email protected]?main=browser:275:35)
        at Zone.runTask (https://unpkg.com/[email protected]?main=browser:151:47)
        at drainMicroTaskQueue (https://unpkg.com/[email protected]?main=browser:418:35)
        at XMLHttpRequest.ZoneTask.invoke (https://unpkg.com/[email protected]?main=browser:349:25)
    Error loading http://msoqa05.devlab.ad:8088/home/bl/app.module.js

Maybe I did not understand it, but in order to import angular I need to mapped it inside systemjs.config? Why?

I am trying to downgrade angular2 componenet inside app.module.ts:

import * as angular from 'angular'; 
import { downgradeComponent } from '@angular/upgrade/static';

angular.module('myApp')
    .directive(
        'helloWorld',
        downgradeComponent({component: HelloWorldComponent}) as angular.IDirectiveFactory
    );

The ts compile is fine with that, but the browser not ok with it and I get this error. angular.module is the basic of angularJS?

like image 421
AngularOne Avatar asked Feb 05 '23 02:02

AngularOne


1 Answers

Doing so solved the problem: no need to import angular with systemjs.

import * as _angular_ from 'angular';

declare global {
  const angular: typeof _angular_;
}
like image 77
AngularOne Avatar answered Feb 15 '23 20:02

AngularOne