博客 页面 15

ionic开发细节三则

获取ElementRef要加上{ read: ElementRef }

  @ViewChild("scrollContainer", { read: ElementRef }) scrollContainer: ElementRef;

参考链接:https://segmentfault.com/a/1190000008695459

 

控制<ion-scroll>可使用以下方法:

  scrollToBottom() {
    this.scrollContainer.nativeElement.children[0].scrollTop = this.scrollContainer.nativeElement.children[0].scrollHeight;
  }

 

检测组件更新使用:

changeDetectorRef.detectChanges();

之前使用markForCheck,必须配合定时器一直检查才行,具体原因待探究。

JavaScript arraybuffer转string

ArrayBuffer与字符串的互相转换

ArrayBuffer转为字符串,或者字符串转为ArrayBuffer,有一个前提,即字符串的编码方法是确定的。假定字符串采用UTF-16编码(JavaScript的内部编码方式),可以自己编写转换函数。

// ArrayBuffer转为字符串,参数为ArrayBuffer对象
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint16Array(buf));
}

// 字符串转为ArrayBuffer对象,参数为字符串
function str2ab(str) {
var buf = new ArrayBuffer(str.length*2); // 每个字符占用2个字节
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; i<strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}

原文链接:https://www.cnblogs.com/copperhaze/p/6149041.html

angular显示默认图片

ionic/angular当img src资源404时,显示默认图片的方法:

<img width="300" height="300" src="{{avatarUrl}}" onError="this.src='assets/img/avatar.png'">

 

免费的Ionic/angular主题收集

https://github.com/start-angular/ani-angular-2

清除Discuz!指定积分

update Discuz_common_member_count set extcredits5 = 0

天气功能开发

api选择:

参考:http://goodbai.com/web/UseForecastAndPMDataAPI.html

https://www.zhihu.com/question/20521716

 

最后选择有二:

高德

优点:免费的量足,几乎不用给钱

缺点:没有空气质量数据

 

和风天气

综合来看比较便宜,数据多

图标选择:
https://darkskyapp.github.io/skycons/
http://erikflowers.github.io/weather-icons/

ionic ios上状态栏和app重叠

官方issues:

https://github.com/ionic-team/ionic/issues/13294

解决办法:

在 config.xml 中添加
<platform name=”ios”>
<preference name=”StatusBarOverlaysWebView” value=”false” />
</platform>

或者通过状态栏插件设置
this.statusBar.overlaysWebView(false);

 

使用angular浏览本地图片

参考:http://blog.csdn.net/xiaotuni/article/details/77461701

 

angular中clearTimeout不生效的问题

之前使用setTimeout、clearTimeout都是正常的,但这次却无法清除定时器了

右键跳转到定义,发现使用的是:

declare function clearTimeout(timeoutId: NodeJS.Timer): void;

这是node端用的定时器。

正确应该调用的是window.clearTimeout,这是前端用的定时器

原因:

安装了@types/node所致

解决办法:

使用window.setTimeout和window.clearTimeout

ionic/cordova编译报内存不足

 

* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at https://docs.gradle.org/4.1/userguide/gradle_daemon.html
Please read the following process output to find out more:
———————–
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap

* Try:
Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output.

* Get more help at https://help.gradle.org

[ERROR] An error occurred while running cordova build android (exit code 1).

 

 

解决办法:

Go to Start -> Control Panel -> System -> Advanced(tab) -> Environment Variables -> System Variables -> New:
Variable name: _JAVA_OPTIONS
Variable value: -Xmx512M

设置好后,需要重启下