http.get本地HTML文件上的Angular 2 - 404

时间:2017-09-26 11:08:12

标签: angular

我在尝试通过http.get获取本地HTML文件时获得404。无法解决问题。代码/筛选作物:

组件:

import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Rx';

//
// Resembles the view for creating and editing card visuals and metadata.
//

@Component({
    selector: 'cards',
    templateUrl: './cards.component.html',
    styleUrls: ['./cards.component.css']
})
export class CardsComponent implements OnInit{
    constructor(public http: Http) { }
    defaultCards: any = [
        {
            name: 'Default',
            frontUrl: './templates/default/front.html',
            backUrl: './templates/default/back.html'
        }
    ];

    ngOnInit() {
        this.http.get('./templates/default/front.html').subscribe(
            (res) => console.log(res.json()),
            (error) => console.log(error));
    }
}

Directory Structure

控制台日志404.非常感谢任何帮助。

0 个答案:

没有答案