I had a very simple 'hello world' Angular2 app. I also made the apparently unreasonable decision to work with different directory structures between my dev project and the final deployment folder on my spring backend.
Because of this difference, I had an issue with the TypeScript imports, and this line ended up producing 404 errors (unable to find /angular2/core library) when I tried to open the actual app in my browser:
import {Component, View} from 'angular2/core';
So long story short, I ended up adding back the /app folder to make everything work, but I ended up modifying my import statements as follows:
import {Component, View} from '../node_modules/angular2/core';
This, however, turned out to cause some weird behavior. For some reason specifying ../node_modules
in the library paths is causing the JS to actually load ALL Angular2 files from scratch using ajax calls to retrieve each and every individual file from the npm_modules/angular2/
folder even though this was part of my HTML header:
<script src="/node_modules/angular2/bundles/angular2.dev.js"></script>
When I finally realized what's going on I reverted the import statement back to
import {Component, View} from 'angular2/core';
and it all worked. Angular2 was now completely loaded from the script tag above and there were no files getting loaded by extra ajax calls.
Can someone please explain what is causing this? I assume it's normal behavior but I don't understand how the importing works and why specifying a more detailed path makes such a difference.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…