2

I followed the directions from angular.io's 5 minute quickstart and everything worked fine. I didn't have to declare .js when I used

import {Component} from 'angular2/core';

I then started using templateUrl to load in other components

import {NavMenuComponent} from '../nav/navMenu';
@Component ({
    selector: 'my-app',
    templateUrl: 'main.html',
    directives: [NavMenuComponent]
})
export class AppComponent {}

When I run the code I get an error saying it could not find localhost:300/src/nav/navMenu

BUT if I add a .js to the end

 import {NavMenuComponent} from '../nav/navMenu.js';

it works fine. I have the index.html already set to..

<script>
    System.config({
        packages: {
            app: {
                format: 'register',
                defaultExtension: 'js'
            }
        }
    });
</script>

Shouldn't that make it so I don't have to use the .js extension on imports anymore? Thanks in advance.

||||||
  • Either change your package in the system config or change the src folder for app – Langley Jan 28 '16 at 21:37
  • @Langley, I do not follow. The angular.io doesn't have a system config file. Can you be more specific on the fix please. – C. Daniel Jan 28 '16 at 21:40
  • not config.js file, the System.config({ packages: { app: { part you have in your code. – Langley Jan 28 '16 at 21:41
  • 1
    Your System.config is specifying to use a default extension of js on stuff under the app package, but for what I see, your component is under src not app : localhost:300/src/nav/navMenu does that make sense? – Langley Jan 28 '16 at 21:58
  • I think I do. so I have to change app to src or create one that says src with a defaultExtension? Is that correct? – C. Daniel Jan 28 '16 at 22:11
0

The solution was exactly what @Langely posted above. Once I added the necessary folders it all worked. In the end I moved it all under one umbrella that handled everything.

app
-- controllers
    -- file.ts
||||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.