While working on a demo for another question on Stack Overflow, I initially used angular-cli and then switched to Plunker.
I noticed a peculiar difference in behavior with the import
statement between the two setups.
The issue arises with the second import
in the code snippet below:
moment.service.ts
import { Injectable } from '@angular/core';
// Works in Plunker setup
import m from 'moment';
// Works in angular-cli setup
// import * as m from 'moment';
@Injectable()
export class MomentService {
moment = m;
}
In the angular-cli environment, I had to use:
import * as m from 'moment';
However, in the Plunker setup, whether running on Plunker or locally, I had to use the following for it to work in the browser:
import m from 'moment';
Can anyone explain this difference in behavior?
Plunker: Link
Github: Plunker code local version (includes a server.js for local hosting)
Github: Angular-cli version