我想知道你如何改变观点。如果我想在index.html
(更改视图)中显示不同的内容,我该怎么做呢?
使用组件和模板是否替换了使用视图的方法?
到目前为止我的app.module中已经有了这个:
const appRoutes: Routes = [
{
path: '',
component: HomeComponent
},
{
path: 'construction',
component: ConstructionComponent
},
{
path: '**',
component: PageNotFoundComponent
}
];
答案 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