在运行时,ionic g page pageName我会生成.ts,.css和.html文件.
在.ts文件中,我有一个调用的函数ionViewDidLoad(){},在我的视图出现之前会打印出来.
我相信这可以在构造函数中完成吗?
有人可以给我一些关于这个功能的博客或解释吗?
当我们不想重新启动已经缓存的任务时,毫无疑问我们将会使用ionDidLoad.
现在,我们假设我们每次进入视图时都需要执行任务,我们如何在使用ionViewWillEntervs 之间做出选择ionViewDidEnter.
我没有找到任何明确的指导方针.
例如:
1)获取navParams
2)调用REST api
3)声明变量
4)完全加载DOM元素后启动一些东西(例如:google map init)
附加说明:
我注意到要在离子文档中明确写出答案.我打算知道的是,如果放入ionViewWillEntervs, 有什么优点和缺点ionViewDidEnter
例如:启动ionViewDidEnter将导致一些延迟(例如,我不确定这一点) - 即使是微不足道的
我想在每次页面更改时执行一些代码.
我可以ngOnDestroy为每个页面添加一个方法.似乎我可以使用Ionic 2页面生命周期钩子(例如ionViewDidUnload)获得完全相同的效果,但我没有费心去测试它.我宁愿在主app类中添加一个方法.
我看到你可以订阅Angular 2 路由器事件.如何翻译用于Ionic 2?我首先得到一个错误import { Router } from '@angular/router;:
TypeScript error: <path>/node_modules/@angular/router/src/common_router_providers.d.ts(9,55): Error TS2305: Module '"<path>/node_modules/@angular/core/index"' has no exported member 'NgModuleFactoryLoader'.
TypeScript error: <path>/node_modules/@angular/router/src/router.d.ts(14,39): Error TS2305: Module '"<path>/node_modules/@angular/core/index"' has no exported member 'NgModuleFactoryLoader'.
TypeScript error: <path>/node_modules/@angular/router/src/router_module.d.ts(9,10): Error TS2305: Module '"<path>/node_modules/@angular/core/index"' has no exported member 'ModuleWithProviders'.
Run Code Online (Sandbox Code Playgroud)
webpack配置
var path = require('path');
module.exports = {
entry: [
path.normalize('es6-shim/es6-shim.min'),
'reflect-metadata',
path.normalize('zone.js/dist/zone'),
path.resolve('app/app.ts')
],
output: {
path: path.resolve('www/build/js'),
filename: 'app.bundle.js',
pathinfo: false …Run Code Online (Sandbox Code Playgroud) 当用户单击图像的共享按钮时,我试图让"离子"应用程序出现在"共享"列表中.
据我所知,我必须添加类似的东西
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
到了AndroidManifest.xml.我认为,我可以使用cordova-custom-config插件.
然后,我必须以某种方式处理这个意图,这对我来说是棘手的.看起来像目前为意图维护的唯一的cordova插件就是这个.我尝试过这样使用它:
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.splashScreen.hide();
this.registerBroadcastReceiver();
});
}
private registerBroadcastReceiver(){
window.plugins.intentShim.registerBroadcastReceiver({
filterActions: [
'com.darryncampbell.cordova.plugin.broadcastIntent.ACTION'
]
},
function(intent) {
// Broadcast received
console.log('Received Intent: ' + JSON.stringify(intent.extras));
}
);
}
Run Code Online (Sandbox Code Playgroud)
但是这样我得到一个错误,即window.plugins是未定义的.我真的不知道如何将它与Ionic结合起来. …
不要将此问题标记为重复,stackoverflow上的任何答案都不 适合我.其中很多是针对Ionic 1或者那些答案已被弃用或者它们不适用于Android设备.
我已经在stackoverflow上看到很多关于获取设备当前位置的解决方案,但是没有解决方案似乎适用于Android.
我试过的: -
使用geolocation.getCurrentPosition(),适用于IOS和浏览器,但不适用于Android.
使用this.geolocation.watchPosition() ,适用于IOS和浏览器,但不适用于Android.
使用navigator.geolocation.getCurrentPosition(),适用于IOS和浏览器,但不适用于Android.
使用此问题提供的小提琴解决方案getCurrentPosition()和watchPosition()在不安全的起源上被弃用
无论如何,所有这些都被谷歌弃用,原因是: -
getCurrentPosition()和watchPosition()在不安全的起源上被弃用,将来会删除支持.您应该考虑将应用程序切换到安全的来源,例如HTTPS.有关详细信息,请参阅goo.gl/rStTGz.
background-geolocation plugin但是,它在Android设备上花费了近50-55秒,再次它对ios工作正常 这个问题joshmorony(https://www.joshmorony.com/adding-background-geolocation-to-an-ionic-2-application/)解决方案前景不工作为Android物理设备,但做工精细的浏览器和iOS.背景跟踪工作正常,这是第一次花费将近50秒的时间来进行拉动.
请帮我解决一下这个.我想要一种在最短时间内获得当前位置的方法.对于您的信息,我使用谷歌javascript地图sdk/api.
就在几天前,我已成功将Ionic应用程序上传到Apple Store,并且在这一天,我收到验证警告:
该应用在Payload / something.app / something中引用了非公共选择器:_setAlwaysRunsAtForegroundPriority:
虽然无法解决,但我可以将应用程序上传到App Store。
是否有人知道它的记录位置或对如何解决有任何见解?
谢谢。
我从angular2和ionic2开始;
在ionic2中,我有一个按钮,可以调用我的组件的方法.像这样:
<button secondary clear large>
</button>
Run Code Online (Sandbox Code Playgroud)
我应该使用(click)- angular2 OR (tap) - ionic2?
像这样:
(click)
<button secondary clear large (click)="pause()">
</button>
Run Code Online (Sandbox Code Playgroud)
(tap)
<button secondary clear large (tap)="pause()">
</button>
Run Code Online (Sandbox Code Playgroud)
有一些区别吗?您可以(tap)在
http://ionicframework.com/docs/v2/components/#gestures中看到
谢谢.
我偶尔会遇到以下错误.
ERROR Error: Uncaught (in promise): invalid link:MenuPage
at d (polyfills.js:3)
at l (polyfills.js:3)
at Object.reject (polyfills.js:3)
at NavControllerBase._fireError (nav-controller-base.js:322)
at NavControllerBase._failed (nav-controller-base.js:310)
at nav-controller-base.js:365
at t.invoke (polyfills.js:3)
at Object.onInvoke (core.es5.js:4125)
at t.invoke (polyfills.js:3)
at n.run (polyfills.js:3)
at polyfills.js:3
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (core.es5.js:4116)
at t.invokeTask (polyfills.js:3)
at n.runTask (polyfills.js:3)
Run Code Online (Sandbox Code Playgroud)
我不知道有任何重现的步骤,这个错误根本没有引起任何问题该应用程序正常工作,菜单页面显示正确.
import { Component, ViewChild } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Nav, Platform } from 'ionic-angular';
@IonicPage({
name: "menu",
segment: …Run Code Online (Sandbox Code Playgroud) 我正在打开.xcworkspace我的Ionic 3项目并尝试在我的设备上运行它,但我突然在Xcode中收到以下错误:
Ld /Users/manuel/Library/Developer/Xcode/DerivedData/MyApp-awaxbzztsgokklgptpuoufwcwmkt/Build/Products/Debug-iphoneos/MyApp.app/MyApp normal arm64
cd /Users/manuel/Documents/MyApp/dev/copernic4-ion2/galilei/platforms/ios
export IPHONEOS_DEPLOYMENT_TARGET=9.0
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk -L/Users/manuel/Library/Developer/Xcode/DerivedData/MyApp-awaxbzztsgokklgptpuoufwcwmkt/Build/Products/Debug-iphoneos -L/Users/manuel/Documents/MyApp/dev/copernic4-ion2/galilei/platforms/ios/MyApp/Plugins/cordova-plugin-google-analytics -F/Users/manuel/Library/Developer/Xcode/DerivedData/MyApp-awaxbzztsgokklgptpuoufwcwmkt/Build/Products/Debug-iphoneos -F/Users/manuel/Documents/MyApp/dev/copernic4-ion2/galilei/platforms/ios/Pods/OneSignal/iOS_SDK/OneSignalSDK/Framework -FMyApp/Plugins/com.googlemaps.ios -filelist /Users/manuel/Library/Developer/Xcode/DerivedData/MyApp-awaxbzztsgokklgptpuoufwcwmkt/Build/Intermediates/MyApp.build/Debug-iphoneos/MyApp.build/Objects-normal/arm64/MyApp.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -miphoneos-version-min=9.0 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/manuel/Library/Developer/Xcode/DerivedData/MyApp-awaxbzztsgokklgptpuoufwcwmkt/Build/Intermediates/MyApp.build/Debug-iphoneos/MyApp.build/Objects-normal/arm64/MyApp_lto.o -Xlinker -no_deduplicate -fobjc-arc -fobjc-link-runtime -ObjC -ObjC -framework OneSignal -framework SystemConfiguration -framework UIKit -framework UserNotifications /Users/manuel/Library/Developer/Xcode/DerivedData/MyApp-awaxbzztsgokklgptpuoufwcwmkt/Build/Products/Debug-iphoneos/libCordova.a -framework Accelerate -framework CoreData -framework CoreLocation -framework CoreText -framework GLKit -framework ImageIO -lc++ -lz -framework OpenGLES -framework QuartzCore -framework SystemConfiguration -framework UIKit -framework GoogleMapsBase -framework GoogleMaps -framework GoogleMapsCore -framework …Run Code Online (Sandbox Code Playgroud)