typescript 新建angular项目如何设置主页

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47448382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:03:46  来源:igfitidea点击:

New angular project how to set home page

htmlangulartypescript

提问by Sam Hanson

I am new to angular

我是 angular 的新手

I have created the new project by using this link https://cli.angular.io/

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

Here the home page is displayed from appcomponent.html

这里的主页显示从 appcomponent.html

I have created the new page in SRC >> pages >> index.html and index.ts

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

I import these pages in appcomponent.tsand appmodule.ts

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

How to set the default home page as index.

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

this is my app component page

这是我的应用组件页面

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 ) {

    }
  }

回答by radoix

You have to generate a new Component with ng g c MyComponent. Then add <router-outlet></router-outlet>to your app.component.html file. Finally you have to configure your Router to display this component at your main address (at localhost:4200). Object should look like

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

const routesConfig: Routes = [
    { path: '',     component: MyComponent}
    ]

Read more about Router and Routing https://angular.io/guide/router

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

回答by Deepak

in app-rounting.module.ts

在 app-routing.module.ts

{path: "",  component: DashboardComponent, pathMatch: "full"},