github 页面上的 Angular2 应用程序中的路径问题
Path issue in Angular2 app on github pages
我是 Angular2 的新手,打算在 github 页面上设置一个小型 Angular2 应用程序(目前是 helloworld)。
我通过 angular-cli
创建了 ng2-lite
,托管在 site。部署由 angular-cli
提供。它部署到 gh-pages
分支进行显示。
最近我发现了angular-cli
以外的另一种方式。我使用类似的代码从头开始创建 ng2-raw
,但没有任何部署操作,托管在 site
但是我在创建 ng2-raw
时遇到了一些问题。调试后,通过相对路径找不到css
或html
(与ts
在同一个路径下),所以我修改路径使其工作。
请查看我的两个 repo 中的不同代码:
github.com/MoYummy/ng2-lite/blob/master/src/app/hello.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'hello',
templateUrl: './hello.component.html',
styleUrls: ['./hello.component.css']
})
export class HelloComponent {
name: string = 'World';
}
github.com/MoYummy/ng2-raw/blob/gh-pages/helloworld/app/hello.component.ts
import {Component} from 'angular2/core';
@Component({
selector: 'hello',
templateUrl: './app/hello.component.html',
styleUrls: ['./app/hello.component.css']
})
export class HelloComponent {
name: string = 'ng2';
}
为什么我必须更新这些路径?如果将来代码结构变得复杂或者我尝试将一个组件移动到子文件夹怎么办?
部署我的 Angular2 应用程序的两种方式有什么区别?
我是 Angular2 的新手,打算在 github 页面上设置一个小型 Angular2 应用程序(目前是 helloworld)。
我通过 angular-cli
创建了 ng2-lite
,托管在 site。部署由 angular-cli
提供。它部署到 gh-pages
分支进行显示。
最近我发现了angular-cli
以外的另一种方式。我使用类似的代码从头开始创建 ng2-raw
,但没有任何部署操作,托管在 site
但是我在创建 ng2-raw
时遇到了一些问题。调试后,通过相对路径找不到css
或html
(与ts
在同一个路径下),所以我修改路径使其工作。
请查看我的两个 repo 中的不同代码:
github.com/MoYummy/ng2-lite/blob/master/src/app/hello.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'hello',
templateUrl: './hello.component.html',
styleUrls: ['./hello.component.css']
})
export class HelloComponent {
name: string = 'World';
}
github.com/MoYummy/ng2-raw/blob/gh-pages/helloworld/app/hello.component.ts
import {Component} from 'angular2/core';
@Component({
selector: 'hello',
templateUrl: './app/hello.component.html',
styleUrls: ['./app/hello.component.css']
})
export class HelloComponent {
name: string = 'ng2';
}
为什么我必须更新这些路径?如果将来代码结构变得复杂或者我尝试将一个组件移动到子文件夹怎么办?
部署我的 Angular2 应用程序的两种方式有什么区别?