NG-ZORRO的layout布局、手机和pc端不一样布局的策略、angular5架构下使用Jsonp的过程当中相关问题、angualr5架构下的百度地图api使用记录。css
版本0.6.x,当前支持 Angular ^5.0.0 版本,查看文档html
$ npm install ng-zorro-antd --save
git
电脑页面使用下面的布局:github
因为不想调整样式,因此配合bootstrap.css一块儿使用.正则表达式
考虑过响应式布局,但要写不少css的媒体查询,直接使用bootstrap有时没法获得本身想要的效果,因此最终决定使用下面的策略。npm
编写一个service,在其中编写一个方法来判断请求来自手机仍是pc,主要使用request中带的userAgent,代码以下:json
isMobilef() {
const ua = navigator.userAgent;
const isAndroid = /Android/i.test(ua);
const isBlackBerry = /BlackBerry/i.test(ua);
const isWindowPhone = /IEMobile/i.test(ua);
const isIOS = /iPhone|iPad|iPod/i.test(ua);
const isM = /Mobile/i.test(ua);
const isMobile = isM || isAndroid || isBlackBerry || isWindowPhone || isIOS;
return isMobile;
}
复制代码
代码是借鉴的网上的,感受写的有点丑陋,我记得之前看见过一行正则表达式就解决的,但愿你们在评论中指点一下。bootstrap
在constructor方法中编写以下代码:api
isMobile = false;
isCollapsed = false;
constructor(private endkindservice: EndkindService) {
console.log(navigator.userAgent);
this.isMobile = this.endkindservice.isMobilef();
console.log(this.isMobile);
}
复制代码
每次加载页面都会判断是手机仍是pc,配合angular的*ngif指令进行布局。bash
angular5之后将http相关的功能封装到了@angular/common/http
包中,通常的网络请求使用HttpClientModule, HttpClientJsonpModule
这两个模块便可。
关键代码:
app.module.ts
...
import {HttpClientModule, HttpClientJsonpModule} from '@angular/common/http';
@NgModule({
declarations: [
...
],
imports: [
...,
HttpClientModule,
HttpClientJsonpModule,
...
],
providers: [...],
bootstrap: [AppComponent]
})
export class AppModule {
}
复制代码
data.service.ts
...
constructor(private http: HttpClient) {
}
...
public getData(): Promise<any> {
const url = '';
return this.http.jsonp(url, 'callback').toPromise().then(res => {
return res;
});
}
复制代码
代码记录
//.html,在外面套一层,固定外面一层的大小
<nz-content>
<baidu-map [options]="opts">
<marker *ngFor="let marker of markers; index as i" [point]="marker.point" [options]="marker.options" (clicked)="showWindow($event,i)"></marker>
<control type="navigation" [options]="controlOpts"></control>
<control type="overviewmap" [options]="overviewmapOpts"></control>
<control type="scale" [options]="scaleOpts"></control>
<control type="maptype" [options]="mapTypeOpts"></control>
</baidu-map>
</nz-content>
//.css,高度100%
nz-content{
background-color: #fff;
width: 100%;
position: absolute;
top: 48px;
bottom: 0px;
left: 0px;
}
复制代码