Angular 2 Final Release Visual Studio - cannot fin

2019-09-16 07:51发布

问题:

I just upgraded to the Angular 2 Final Release (I am using Visual Studio 2015 and TypeScript 1.8) and noticed my line moduleId: module.id in my components now has the red squiggly underline and say cannot find name 'module'.

In the network tab in Chrome I see that the templateUrl and styleUrls paths are both incorrect.

This is my working component:

@Component({
    selector: 'dashboard',
    moduleId: module.id,
    templateUrl: 'dashboard.component.html',
    styleUrls: ['dashboard.component.css'],
    styles: ['.chart {display: block; width: 100%;} .title.handle{background-color:transparent;}']

})

**But when I remove the line moduleId: module.id I get a 404 error because it is looking for:

http://localhost:56159/dashboard.component.css and http://localhost:56159/dashboard.component.html

Any help would be appreciated!

thank you

回答1:

try this, giving those two files paths these ./ in front of them

@Component({
    selector: 'dashboard',
    templateUrl: './dashboard.component.html',
    styleUrls: ['./dashboard.component.css'],
    styles: ['.chart {display: block; width: 100%;} .title.handle{background-color:transparent;}']

})


回答2:

You will need to reference the Node definition typescript file. Node TypeScript Definition

As you can see module is defined at line 70

declare var module: NodeModule;


标签: angular