我EventFeedbackComponent通过ModalController 显示一个Component .现在我想订阅一个Subjectin EventFeedbackComponent.如何访问组件实例,以实现我的目标.
我目前的代码:
let modal = this.modalCtrl.create(EventFeedbackComponent);
modal.present();
// This is not working. Throws the error "ERROR TypeError: Cannot read property 'subscribe' of undefined"
modal._component.feedbackSubmit.subscribe(feedbackResponse => {
console.log(feedbackResponse);
});
Run Code Online (Sandbox Code Playgroud)
文档在这方面没有帮助:https://ionicframework.com/docs/api/components/modal/ModalController/
我的用例:
Service,我需要获得反馈.EventFeedbackComponent 有控件来获取单个事件的反馈.feedbackSubmit通过来监听事件Subjectfeedback,我会显示一个成功Toast并在Service中切换我的服务变量以显示下一个事件.我已经看过像rxjs这样的教程.
我的问题是:
1)take(1)这里的用法是什么?我在网上看到了很多解释,但我并没有真正理解.此外,我认为take(1)在此代码中使用没有任何好处.并且作者take(1)在REST api相关服务中使用每个返回函数.
2)作者在订阅后没有取消订阅.是因为作者使用take(1)因此不需要手动取消订阅?
3)如果我想实现catch功能怎么办?我应该在服用前或服用后实施.
getProfile() { // this is a call to REST API
return this.service.getProfile()
.map(res => res.json())
.take(1)
}
}
this.data.getProfile().subscribe(profile => {
this.userProfile = profile;
});
Run Code Online (Sandbox Code Playgroud) 我正在阅读有关本地存储的内容,我很困惑.我认为有两种选择:
本机存储,导入{NativeStorage}离子存储,导入{IonicStorageModule}我的应用程序是用Ionic 3开发的,我试图在从Parse Server检索它后保存一个对象localy数组.
使用Ionic 1,我存储了像这样的对象数组:
setUsers (users){
window.localStorage.users_data = JSON.stringify(users);
}
getUsers(){
return JSON.parse(window.localStorage.users_data || '[]');
}
Run Code Online (Sandbox Code Playgroud)
那么现在,保存我的数据并将它们串起来并解析它们的最佳选择是什么?
原生存储或离子存储?
非常感谢
现在,使用Angular v5,同时使用延迟加载,我加载app.module.ts我认为不是最佳策略的所有提供者,因为这不会加快我的应用程序启动时间,特别是因为我有50个自定义的东西提供者(不要评判我;)).
因此,我问我自己是否应该为我的所有应用程序加载所有这些应用程序,或者我是否应该只在我只使用它们的地方加载它们?
我猜测只在我真正使用它们的地方加载提供商会更好.
但在这种情况下,对我而言根本不清楚如何解决以下构造:
假设我有三个页面(A,B和C),它们有自己的模块和三个提供程序(1,2和3).
A use 1
B use 1, 2, 3
C use 1, 2
Run Code Online (Sandbox Code Playgroud)
我想,因为1是在所有应用程序中使用,我将不得不声明它 app.module.ts
由于3只在B页中使用,我想我只需要声明它 B.module.ts
但是2呢?我怎么能在两者中声明它B.module.ts并且C.module.ts目标是共享相同的提供者"内存"(如果提供者包含一个值,B和C应该看到相同的对象),我将分别如何编码?只需通过"像往常一样"注入提供者并完成剩下的角度吗?
提前获得任何帮助,真的很感激
UPDATE
不确定我是否正确理解了角度文档,但这是目标,应该为所有应用程序加载提供程序吗?
看到
https://angular.io/guide/ngmodule-faq#q-component-scoped-providers
更新2018年
注入策略随着Angular v6的引入而发展.根据文档,可以providedIn指定应该使用服务的模块.请参阅https://angular.io/guide/dependency-injection
所以,我在Android Studio中有一个项目,我在插件中使用它,它通过aar文件在Ionic项目中使用.我通过单击Android Studio右侧(其中显示Graddle)生成aar文件,扩展我的项目/任务/构建,然后单击汇编版本.Graddle开始工作,我在myProject/build/outputs/aar中有一个aar文件.一段时间没关系.我在该代码中检测到了一些错误,纠正了它们,并再次生成了aar.
然后,我将该aar文件复制并粘贴到plugin.xml文件中指定的文件夹中:
<resource-file src="aar/library.aar" target="aar/library.aar" />
Run Code Online (Sandbox Code Playgroud)
然后,我使用packagr编译项目(插件,我应该说):
"packagr": "ng-packagr -p package.json && cd dist && npm pack && move *.tgz ../../"
Run Code Online (Sandbox Code Playgroud)
这样,生成了tgz文件.之后,我转到项目根目录(使用该插件的那个)并且执行
npm install @namespace/my-plugin-name
Run Code Online (Sandbox Code Playgroud)
一切都很好看.我在一个设备中运行该项目......并且没有反映出aar中的变化.
难道我做错了什么?为什么这些变化没有反映出来?
我有一个严重的问题,我尝试安装离子,cordova,角度,react-native-cli,https-status-error和其他包,它总是返回我:
npm ERR! code E418
npm ERR! 418 I'm a teapot: ionic @ latest
Run Code Online (Sandbox Code Playgroud)
请问我可能是错的,我不明白发生了什么事,我很好,直到3天前.
它运行在小米Mix 2手机(Android版本8.0.0)和浏览器上没有任何问题.但是当我部署到三星note 2(android版本4.4.2)时,它给出了一条应用程序错误: net :: ERR_CONNECTION_REFUSED(http:// localhost:8080)
为什么我收到此错误?
任何建议和意见将不胜感激.
凯末尔.
我让Ionic 3正常工作了几个月,并且上周更新到Ionic 4进行了测试。我的应用程序是用Ionic 3编写的。现在,ionic cordova build android不更新构建。离子发球效果很好。
我能够ionic cordova build android像其他所有离子命令一样正常运行,但是运行构建时,构建不会更新。使它更新的唯一方法是删除并重新添加平台。我还确保在运行模拟器后从模拟器中卸载该应用程序-因此它不会访问旧版本。此外,在该/platforms/android文件夹中,没有文件被更新。
我尝试了以下方法:
重新安装了Gradle(也通过brew)
完成上述所有操作后,重新启动计算机。
重置PATH变量(如下),并尝试使用Ionic-cli 3.20。*和4.0.5运行构建。
离子信息:
Ionic:
ionic (Ionic CLI) : 4.0.5 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.1.11
Cordova:
cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 7.0.0
System:
Android SDK Tools : 26.1.1
NodeJS : v10.8.0 (/usr/local/Cellar/node/10.8.0/bin/node)
npm : 6.3.0
OS : macOS High Sierra
Xcode : Xcode 9.4.1 Build version 9F2000 …Run Code Online (Sandbox Code Playgroud) 无法解析配置“ classpath”的所有文件。
找不到com.google.android.gms:strict-version-matcher-plugin:1.1.0。
Searched in the following locations: https://jcenter.bintray.com/com/google/android/gms/strict-version-matcher-plugin/1.1.0/strict-version-matcher-plugin-1.1.0.pom https://jcenter.bintray.com/com/google/android/gms/strict-version-matcher-plugin/1.1.0/strict-version-matcher-plugin-1.1.0.jar file:/C:/Users/e1706396/.m2/repository/com/google/android/gms/strict-version-matcher-plugin/1.1.0/strict-version-matcher-plugin-1.1.0.pom file:/C:/Users/e1706396/.m2/repository/com/google/android/gms/strict-version-matcher-plugin/1.1.0/strict-version-matcher-plugin-1.1.0.jar Required by: unspecified:unspecified:unspecified > com.google.gms:google-services:4.2.0
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
在https://help.gradle.org上获得更多帮助
7s cmd中的BUILD FAILED:命令失败,退出代码为1
我正在使用插件
<plugin name="cordova-plugin-appavailability" spec="^0.4.2" />
<plugin name="cordova-plugin-camera" spec="^4.0.3" />
<plugin name="cordova-plugin-compat" spec="^1.2.0" />
<plugin name="cordova-plugin-device" spec="^2.0.2" />
<plugin name="cordova-plugin-googleplus" spec="^5.2.1">
<variable name="REVERSED_CLIENT_ID" value="xxx" />
</plugin>
<plugin name="cordova-plugin-ionic-keyboard" spec="^2.0.5" />
<plugin name="cordova-plugin-ionic-webview" spec="^1.1.19" />
<plugin name="cordova-plugin-mfp" spec="^8.0.2018070216" …Run Code Online (Sandbox Code Playgroud)对于任何带有角度的离子模式,都会有一些代码被延迟加载。
以吐司为例。当您单击“配对”按钮时,将加载三个javascript文件(请参见下面的屏幕截图)。第二次单击“对”时,不会加载其他文件。
这对我来说是有问题的,因为我想在检测到Internet连接问题时向您展示祝酒词,因此需要完全预载祝酒词的代码。我不知道该怎么做。鉴于angular的延迟加载是基于路由的,所以我不了解烤面包机如何甚至可以开始使用延迟加载的代码。
编辑:我知道显示隐藏的吐司将以一种hacky的方式解决该问题,但我对延迟加载系统的工作方式特别感兴趣
ionic-framework ×10
angular ×5
ionic3 ×5
android ×4
typescript ×2
aar ×1
cordova ×1
ionic-cli ×1
ionic-native ×1
ionic2 ×1
ionic4 ×1
npm ×1
rxjs ×1