我試圖建立自己的角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