Ionic 2 相关学习

基础

问题

1
2
3
4
5
6
7
8
9
10
11
metadata_resolver.js:499 Uncaught Error: Can't resolve all parameters for Project: (?, ?).
at CompileMetadataResolver.getDependenciesMetadata (http://localhost:8100/build/main.js:23905:19)
at CompileMetadataResolver.getTypeMetadata (http://localhost:8100/build/main.js:23806:26)
at http://localhost:8100/build/main.js:23949:41
at Array.forEach (native)
at CompileMetadataResolver.getProvidersMetadata (http://localhost:8100/build/main.js:23929:19)
at CompileMetadataResolver.getDirectiveMetadata (http://localhost:8100/build/main.js:23569:34)
at http://localhost:8100/build/main.js:23674:49
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:8100/build/main.js:23668:49)
at RuntimeCompiler._compileComponents (http://localhost:8100/build/main.js:39512:47)

如,将:

1
2
3
4
5
@Component({
selector: 'page-prj-detail',
templateUrl: 'prj-detail.html',
providers: [Project]
}

改为:

1
2
3
4
5
@Component({
selector: 'page-prj-detail',
templateUrl: 'prj-detail.html',
providers: [ProjectService]
}
  • 遇到这个错误,可能是html界面的方法与ts中的方法对不上。
1
2
3
4
5
6
7
8
9
10
11
polyfills.js:3 Uncaught TypeError: exceptionHandler.handleError is not a function
at Object.next (http://localhost:8100/build/main.js:26130:82)
at SafeSubscriber.schedulerFn [as _next] (http://localhost:8100/build/main.js:27643:52)
at SafeSubscriber.__tryOrUnsub (http://localhost:8100/build/main.js:9761:16)
at SafeSubscriber.next (http://localhost:8100/build/main.js:9710:22)
at Subscriber._next (http://localhost:8100/build/main.js:9663:26)
at Subscriber.next (http://localhost:8100/build/main.js:9627:18)
at EventEmitter.Subject.next (http://localhost:8100/build/main.js:11949:25)
at EventEmitter.emit (http://localhost:8100/build/main.js:27635:76)
at NgZone.triggerError (http://localhost:8100/build/main.js:28451:76)
at Object.onHandleError (http://localhost:8100/build/main.js:28430:23)
  • 编译时遇到这个错误:
1
2
3
4
5
[23:13:04]  Error: Error at [project path]/.tmp/pages/statis/projects.ngfactory.ts:351:29
[23:13:04] Supplied parameters do not match any signature of call target.
[23:13:04] ngc failed
[23:13:04] ionic-app-script task: "build"
[23:13:04] Error: Error

一般说明在程序的某处有个方法需求的参数与提供的参数对应不上,在build时无法通过,但在ionic serve时可正常运行,这个错误就比较难找了。这里注意看错误提示,说的是

1
.tmp/pages/statis/projects.ngfactory.ts

那么就去检查 /pages/statis/projects.ts 文件中的相应方法的参数吧!

  • 编译时遇到这个错误:

    1
    2
    3
    4
    5
     FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':packageDebug'.
    > java.io.FileNotFoundException: /Users/samliu/gits/jing-xi-h5/platforms/android/build/intermediates/assets/debug/www/assets/stub (Is a directory)

这个错误原因不明,但通常再次编译运行就好了。

  • 调试时遇到这个错误:
1
2
Application Error
There was a network error (http://192.168.56.1)

网上查到答案是要添加whitelist的插件{:target=”_blank”},然后添加相应的网址到config.xml中。

  • 发现这个错误,一般是 queries.sql 里面的SQL写错了。
1
ERROR Can not issue data manipulation statements with executeQuery()

原因是修改性的SQL语句,上面的声明要用“!”,而不能用“?”。

  • 遇到这个错:

    1
    2
    3
     Can't bind to 'ngShow' since it isn't a known property of 'ion-list'.
    1. If 'ion-list' is an Angular component and it has 'ngShow' input, then verify that it is part of this module.
    2. If 'ion-list' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message.

应该是说 ngShow 并不支持这样的写法,后改为 *ngIf即可。

  • 遇到这个错:Can’t coerce body of type class java.lang.Integer

    是因为返回的数据不是json,比如直接将db操作的update结果1返回给客户端,这里(ok 1)就会报这个错,改为:(ok {:success 1}) 即可。

  • 遇到这个错:Unable to find localabstract name of cordova app

参考此回复

1
vim .vscode/extensions/vsmobile.cordova-tools-1.2.4/out/src/debugger/cordovaDebugAdapter.js

在 254 行,修改为

1
2
3
4
// if (socketsInodes.indexOf(parseInt(fields[6], 10)) === -1) {
if (pathField.indexOf(pid) === -1) {
continue;
}
赞赏留名,相识相惜 ~