I'm trying to build my own Angular 2/ASP.NET SPA on Visual Studio. You can find all the files here.
What I tried to do is simple: after I followed the instructions to set up the app here, I began to add in my own files in an attempt to do some basic routing and I deleted some superfluous files. I have ClientApp/app/app.module.ts bootstrapping ClientApp/app/components/app/app.component.ts, and the only route is ClientApp/app/components/app/test.component.ts
Unfortunately, I got this error:
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)
Everything looks right to me, but I'm new to both Angular 2 and ASP.NET, so I don't know if it is a compiler issue or human error. Here is some of the code, if you need more information the link to the repo is at the top of this question.
ClientApp/app/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/components/app/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/components/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";
}
}
The UniversalModule currently requires that external assets for templates and styles use require().
Try changing templateUrl: './test.component.html'
to template: require('./test.component.html')
.
And styleUrls: ['./test.component.css']
to styles: [require('./test.component.css')]
More details on the issue can be found here: Unable to load assets without using require()
For reference, here is the issue thread from Angular on Github: track runtime styleUrls. They recommend using the angular2-template-loader.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With