无法找到模板

时间:2016-10-18 18:45:39

标签: javascript angularjs

我在这里提出几个问题,试图解决我的问题。最初,我希望得到这个错误:

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

我看了这两个问题,并得出结论我在配置中缺少一些额外的属性:

Angular2 Rxjs 404 errorWhere is angular2-polyfills now that non-beta Angular 2 is packaged as @angular?

为了摆脱rxjs 404,我必须在 systemjs.config.js 中添加的缺失属性如下:

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

但是,现在我一直收到zone.js文件的错误,说明我的模板无处可寻。

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

我在此代码中使用此模板: /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"));
    }

}

我的模板位于: app / templates / 下,名为 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>

如何摆脱此错误?我是否需要设置另一个要加载的zone.js文件?

1 个答案:

答案 0 :(得分:1)

目前,您已设置相对于当前路径的引用。尝试设置模板url absolute:

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

也可能是因为您的服务器设置的根本不是您认为的根本。检查您的服务器设置。

相关问题