我试图建立自己的角2/ASP.NET SPA在Visual Studio中。你可以找到所有的文件here。Angular2/ASP.NET - “没有的ResourceLoader实现已经提供了无法读取URL。”
我试图做的很简单:在我按照说明设置应用程序here后,我开始在自己的文件中添加以尝试执行一些基本路由,并删除了一些多余的文件。我有ClientApp/app/app.module.ts bootstrapping ClientApp/app/components/app/app.component.ts,唯一路由是ClientApp/app/components/app/test.component.ts
不幸的是,我得到这个错误:
An unhandled exception occurred while processing the request.
Exception: Call to Node module failed with error: Error: No ResourceLoader implementation has been provided. Can't read the url "app.component.html"
at Object.get (C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:17454:17)
at DirectiveNormalizer._fetch (C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:13455:45)
at DirectiveNormalizer.normalizeTemplateAsync (C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:13498:23)
at DirectiveNormalizer.normalizeDirective (C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:13473:46)
at RuntimeCompiler._createCompiledTemplate (C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:16869:210)
at C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:16807:43
at Array.forEach (native)
at C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:16805:50
at Array.forEach (native)
at RuntimeCompiler._compileComponents (C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:16804:45)
一切看起来正确的给我,但我是新来的两个角2和ASP.NET,所以我不知道这是否是一个编译器问题或人为错误。下面是一些代码,如果你需要了解更多信息的链接回购是在这个问题的顶部。
ClientApp /应用/ app.module.ts
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { UniversalModule } from 'angular2-universal';
import { AppComponent } from './components/app/app.component';
import { TestComponent } from './components/app/test.component';
@NgModule({
bootstrap: [ AppComponent ],
declarations: [
AppComponent,
TestComponent
],
imports: [
UniversalModule, // Must be first import. This automatically imports BrowserModule, HttpModule, and JsonpModule too.
RouterModule.forRoot([
{ path: 'test', component: TestComponent },
{ path: '', redirectTo: 'test', pathMatch: 'full' },
{ path: '**', redirectTo: 'test' }
])
]
})
export class AppModule {
}
ClientApp /应用/组件/应用程序/ app.component.ts
import { Component, Input } from '@angular/core';
@Component({
selector: 'app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
}
ClientApp /应用/组件/app/test.component.ts
import {Component, Input, OnInit} from '@angular/core';
@Component({
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
testing: String;
ngOnInit(): void {
this.testing = "This Works";
}
}
是否'app.component.html'存在吗?你在代码中引用它,但是你创建了它吗? –
是的,它和app.component.ts在同一个文件夹中 –
你有没有找到这个的原因?遇到同样的问题w/yeoman生成的项目。 – ohlando