新建angular项目如何设置主页

Sam*_*son 3 html typescript angular

我是 angular 的新手

我使用此链接创建了新项目 https://cli.angular.io/

这里的主页显示从 appcomponent.html

我在 SRC >> pages >> index.html 和 index.ts 中创建了新页面

我将这些页面导入appcomponent.tsappmodule.ts

如何将默认主页设置为索引。

这是我的应用组件页面

import { Component } from '@angular/core';
import { Http, Headers } from '@angular/http';
import { IndexPage } from '../pages/index';


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class MyApp {
  title = 'app';
  rootPage:any = IndexPage;


  constructor(    public http: Http ) {

    }
  }
Run Code Online (Sandbox Code Playgroud)

小智 7

您必须使用 ng gc MyComponent 生成一个新组件。然后添加 <router-outlet></router-outlet> 到您的 app.component.html 文件中。最后,您必须配置您的路由器以在您的主要地址(在 localhost:4200)上显示此组件。对象应该看起来像

const routesConfig: Routes = [
    { path: '',     component: MyComponent}
    ]
Run Code Online (Sandbox Code Playgroud)

阅读有关路由器和路由的更多信息https://angular.io/guide/router