首页 > 代码库 > angularJs2随记
angularJs2随记
路由:
调用路由模块
import { NgModule } from ‘@angular/core‘;
import { RouterModule, Routes } from ‘@angular/router‘;
import { RouterModule, Routes } from ‘@angular/router‘;
设置子路由
{ path: ‘home‘, component: HomeComponent ,children:childRoutes},
const childRoutes : Routes=[
{ path: ‘‘, redirectTo: ‘index‘, pathMatch: ‘full‘ },
{ path: ‘index‘, component: IndexComponent }
]
{ 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 {
}
@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 {
}
}
@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;
}
constructor(location: Location) {
this.path = location;
}
调用接口
return this.http.get(‘http://localhost:81/angular.php‘)
.map(response => response.json()).subscribe(data=http://www.mamicode.com/>{
this.res = data.res;
.map(response => response.json()).subscribe(data=http://www.mamicode.com/>{
this.res = data.res;
})
angularJs2随记
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。