標籤:import response init scribe host routes com data 介面
路由:調用路由模組import { NgModule } from ‘@angular/core‘;
import { RouterModule, Routes } from ‘@angular/router‘; 設定子路由{ path: ‘home‘, component: HomeComponent ,children:childRoutes}, const childRoutes : Routes=[
{ path: ‘‘, redirectTo: ‘index‘, pathMatch: ‘full‘ },
{ path: ‘index‘, component: IndexComponent }
] 在需要跳路由的標籤加上屬性 routerLink="home"在需要載入路由的介面添加標籤 <router-outlet></router-outlet>路由跳轉
(這個跳轉的方法,資源不會調用)this.router.navigateByUrl("/home"); 模組:在ts中模組的基本結構如下:import { Component } from ‘@angular/core‘;
@Component({
selector: ‘app-home‘,
templateUrl: ‘./home.component.html‘
})
export class HomeComponent {
}
import { Component, OnInit } from ‘@angular/core‘;
@Component({
selector: ‘my-home‘,
templateUrl: ‘./home.component.html‘
})
export class HomeComponent implements OnInit{
ngOnInit(): void {
}
}
路徑:擷取路徑(/home/index)path:Location;
constructor(location: Location) {
this.path = location;
} 調用介面return this.http.get(‘http://localhost:81/angular.php‘)
.map(response => response.json()).subscribe(data=>{
this.res = data.res;})
angularJs2隨記