Angular 2 CLI 路由不显示 HTML 的内容
Angular 2 CLI route not displaying content of HTML
我使用 Angular2 CLI 创建了一个新项目,还添加了一个名为 item 的路由。现在我尝试通过调用 url http://localhost:4200/item
来访问 html 页面
但它只显示标准:应用正在运行!文本,而不是项目页面的内容。我也试过
http://localhost:4200/#item
结果相同。
我没有更改任何代码,除了 item.component.html。
知道我做错了什么吗,我是否应该在 CLI 处于 alpha 阶段时不使用它?
谢谢
使用 CLI 有点问题,尤其是与新路由器一起使用时,因为它都是积极开发的 atm。
CLI (atm) 无法正确处理自动路由创建。现在我使用一个解决方法:
更新您的 package.json 以使用路由器版本
"@angular/router": "3.0.0-alpha.3"
将 ROUTER_DIRECTIVES 导入您的 parent.component.ts 赞
parent.component.ts
import {ROUTER_DIRECTIVES} from '@angular/router';
其中 parent.component.ts 当然是您最全球化的应用程序组件。不要忘记将 ROUTER_DIRECTIVES 插入到 parent.component.ts 中的指令数组中以获得
<router-outlet></router-outlet>
标签可用。
然后在 main.ts 中,导入 provideRouter 和 RouterConfig 以手动将其添加到引导程序中,如:
//other imports
import {provideRouter, RouterConfig} from '@angular/router';
import {HomeComponent} from './app/+home/home.component';
import {LoginComponent} from './app/+login/login.component';
bootstrap(parent.component.ts, provideRouter([
{path: '/home', component: HomeComponent},
{path: '/login', component: LoginComponent},
])`
我知道它有点丑,但它对我有用,我找不到使用本机路由功能的方法,但是当 angular2 和 CLI 进一步改进时,这可能(希望)改变。
我使用 Angular2 CLI 创建了一个新项目,还添加了一个名为 item 的路由。现在我尝试通过调用 url http://localhost:4200/item
来访问 html 页面但它只显示标准:应用正在运行!文本,而不是项目页面的内容。我也试过 http://localhost:4200/#item 结果相同。
我没有更改任何代码,除了 item.component.html。
知道我做错了什么吗,我是否应该在 CLI 处于 alpha 阶段时不使用它?
谢谢
使用 CLI 有点问题,尤其是与新路由器一起使用时,因为它都是积极开发的 atm。
CLI (atm) 无法正确处理自动路由创建。现在我使用一个解决方法:
更新您的 package.json 以使用路由器版本
"@angular/router": "3.0.0-alpha.3"
将 ROUTER_DIRECTIVES 导入您的 parent.component.ts 赞
parent.component.ts
import {ROUTER_DIRECTIVES} from '@angular/router';
其中 parent.component.ts 当然是您最全球化的应用程序组件。不要忘记将 ROUTER_DIRECTIVES 插入到 parent.component.ts 中的指令数组中以获得
<router-outlet></router-outlet>
标签可用。
然后在 main.ts 中,导入 provideRouter 和 RouterConfig 以手动将其添加到引导程序中,如:
//other imports
import {provideRouter, RouterConfig} from '@angular/router';
import {HomeComponent} from './app/+home/home.component';
import {LoginComponent} from './app/+login/login.component';
bootstrap(parent.component.ts, provideRouter([
{path: '/home', component: HomeComponent},
{path: '/login', component: LoginComponent},
])`
我知道它有点丑,但它对我有用,我找不到使用本机路由功能的方法,但是当 angular2 和 CLI 进一步改进时,这可能(希望)改变。