Angular 2

时间:2016-12-16 14:21:41

标签: angular

我想知道你如何改变观点。如果我想在index.html(更改视图)中显示不同的内容,我该怎么做呢?

使用组件和模板是否替换了使用视图的方法?

到目前为止我的app.module中已经有了这个:

const appRoutes: Routes = [


{
    path: '',
    component: HomeComponent
  },
  {
    path: 'construction',
    component: ConstructionComponent
  },
  { 
    path: '**', 
    component: PageNotFoundComponent 
  }
];

1 个答案:

答案 0 :(得分:1)

视图只是一个HTML文件,其中包含Controller。它在Angular 2中并没有什么不同。

您不再在配置文件中定义HTML View,而是定义Component(相当于Controller),而View现在是Component直接在Component

中定义

因此,为了澄清,您必须定义路径和View,它将呈现您想要的ngOnInit(): void { self.loadingProvider.showLoading();//show spinner getData(); self.loadingProvider.hideLoading(); } getData(){ //code to fetch data from the server } 。就像以前那样。不要犹豫,查看有关routing

的官方文档