angryip angryip - 1 month ago 6
Javascript Question

Unable to find the template

I am following a few questions here, to try and resolve my issue. Originally, I keept getting this error:

GET http://localhost:3000/node_modules/rxjs/ 404 (Not Found)


I them looked at these two questions, and concluded that I am missing some additional properties in the configuration:

Angular2 Rxjs 404 error and Where is angular2-polyfills now that non-beta Angular 2 is packaged as @angular? .

The missing property that I had to add in systemjs.config.js in order to get rid of the rxjs 404, is as follows:

rxjs: {
main: '/bundles/Rx.js',
defaultExtension: 'js'
},


However, now I keep getting an error by the zone.js file stating that my template is nowhere to be found.

zone.js:1274 GET http://localhost:3000/templates/Data.component.tpl.html 404 (Not Found)


I am using this template in this code: /app/components/Data.component.ts

import {Component, Injectable} from '@angular/core';
import {MyService} from "../service/MyService";
import {MyVo} from "../domain/MyVo";

@Component({
selector: 'my-app',
templateUrl: '../templates/Data.component.tpl.html',
providers: [MyService]
})

@Injectable()
export class DataComponent {

public gotData: MyVo [];
constructor(private _myService: MyService) {}

getAllData(): void {
this._myService.getAllData().subscribe(
data => this.gotData= data, error=> console.log(error),
() => console.log("getting all items complete"));
}

}


My template is located under: app/templates/ and is called Data.component.tpl.html

<form (ngSubmit)="getAllData()">
<label>Version Tracks</label>
<button type="submit">Search</button>
</form>
<hr>
<p style="color:red">{{error}}</p>
<h1>All Data</h1>


How do I get rid of this error? Do I need to set a different zone.js file to be loaded?

Answer

Currently you've set your references relative to the current path. Try setting your template url absolute:

templateUrl: './app/templates/Data.component.tpl.html'

It could also be that you've set up your server in a way that its root is not who you think it is. Check your server settings as well.