我在Ionic2项目中以页面的typescript编写的组件具有以下结构:
import { Component, ViewChild, ElementRef } from '@angular/core';
...
declare var google;
@Component({
selector: 'page-search',
templateUrl: 'search.html'
})
export class SearchPage {
@ViewChild('map') mapElement: ElementRef;
map: any;
guideList: Array<Guide>;
text: any;
lat : any;
lon : any;
constructor(public navCtrl: NavController, public recoshService: Recosh, public alertCtrl: AlertController) {
...
}
ngOnInit(){
this.loadMap();
}
loadGuides() {
...
}
setLat(l){
this.recoshService.setLat(l);
this.lat = l;
}
setLon(l){
this.recoshService.setLon(l);
this.lon = l;
}
setPos(lat, lon){
this.setLon(lon);
this.setLat(lat);
this.loadGuides();
}
loadMap(){
...
let marker = …Run Code Online (Sandbox Code Playgroud) 我正在使用以下命令在Android设备上安装应用程序.
"离子cordova运行android"
但是当我安装另一个应用程序时,它正在取代旧的应用程序.
所以请告诉我解决方案,以便旧的和另一个新的应用程序都应该在Android设备中
嗨,我正在尝试着重于搜索输入字段。我已经为此创建了一个指令。它已从directives.module.ts中导出。另外,我将指令。模块导入到app.module.ts中。每当我尝试在ion-searchbar中使用指令时,都会出现以下错误。我不知道我在想什么。
Can't bind to 'focuser' since it isn't a known property of 'ion-searchbar'.
Run Code Online (Sandbox Code Playgroud)
指令.module.ts
import { NgModule } from '@angular/core';
import { FocuserDirective } from './focuser/focuser';
@NgModule({
declarations: [FocuserDirective],
imports: [],
exports: [FocuserDirective]
})
export class DirectivesModule {}
Run Code Online (Sandbox Code Playgroud)
聚焦器
import {Directive, Renderer, ElementRef} from "@angular/core";
/**
* Generated class for the FocuserDirective directive.
*
* See https://angular.io/api/core/Directive for more info on Angular
* Directives.
*/
@Directive({
selector: '[focuser]' // Attribute selector
})
export class FocuserDirective {
constructor(public renderer: Renderer, public …Run Code Online (Sandbox Code Playgroud) typescript ionic-framework angular2-directives ionic3 angular
我的问题:
我的应用程序包含一个启用滑动的菜单.在登录屏幕上,如果我滑动,我可以看到不正确的菜单.我想对不包含菜单图标的页面禁用菜单滑动,例如登录,包含后退按钮的内部详细信息页面等.
解决方案:
我可以通过关注SO链接来做到这一点 - /sf/answers/2705825111/
我创建了一个基类并在其中注入了一个菜单对象.覆盖ionViewDidEnter()和ionViewDidLeave()在子类中,我继承了基类.我必须super()在派生类构造函数中编写调用,并将菜单对象传递回超类.
是他们用这种方式做任何其他方式我必须在每一页都这样做.
请检查以下代码片段:
基类
import { MenuController } from "ionic-angular";
export class BaseComponent {
constructor(public menu: MenuController) {
}
ionViewDidEnter() {
this.menu.swipeEnable(false);
}
ionViewDidLeave() {
this.menu.swipeEnable(true);
}
}
Run Code Online (Sandbox Code Playgroud)
派生类
import { Component } from '@angular/core';
import { NavController, LoadingController, Events, MenuController } from 'ionic-angular';
@Component({
selector: 'login',
templateUrl: 'login.component.html'
})
export class login extends BaseComponent {
constructor(public menu: MenuController) {
super(menu)
}
}
Run Code Online (Sandbox Code Playgroud) 我正试图在我的Android设备上运行我的Ionic 3项目ionic cordova run android --device --stacktrace,但是,我有以下输出:
...
在C:\ Android\android-sdk\licenses中检查软件包Android SDK Platform 26的许可证警告:不接受软件包Android SDK Platform 26的许可证.
FAILURE:构建因异常而失败.
- 出了什么问题:配置根项目'android'时出现问题.
您尚未接受以下SDK组件的许可协议:[Android SDK Platform 26].在构建项目之前,您需要接受许可协议并使用Android Studio SDK Manager完成缺少的组件的安装.或者,要了解如何将许可协议从一个工作站转移到另一个工作站,请访问 http://d.android.com/r/studio-ui/export-licenses.html
阅读其他问题,人们建议使用Android Studio SDK管理器并安装最新版本,因为那时我会被问及许可证并且必须接受它们,所以我安装了Android 8.0(Oreo)和Android API 27,这是最后一个但是,在任何时候我都没有询问任何许可证,并且错误仍然存在.我的设备通过USB电缆连接到PC(Windows 10),启用编程器模式以及USB调试.我该怎么做才能解决这个问题?
我的SDK管理员:
更新:
我已经sdkmanager --licenses在C:\Android\sdk\tools\bin和C:\Users\User\AppData\Local\Android\sdk\tools\bin文件夹中运行了命令,并且接受了所有丢失的许可证,但错误仍在继续.
我的科尔多瓦- Android版本在package.json:"cordova-android": "~6.3.0"在config.xml:<engine name="android" spec="~6.3.0" />(与已经尝试过6.3.0,并6.2.0没有成功)
发生错误后:
在C:\ Android\android-sdk\licenses中检查软件包Android SDK Platform 26的许可证警告:不接受软件包Android SDK Platform 26的许可证.
但我没有许可证文件夹C:\Android\android-sdk,只是在C:\Android\sdk.我如何做离子检查许可证真正的文件夹?
ionic info …
我有一个可以删除另一个用户的应用程序。当用户单击删除按钮时,将出现一个弹出窗口,询问用户是否确定要执行此操作。当用户单击确认时,我希望删除该用户。我最初是通过在按钮上放置remove方法来实现此目的的,如下所示:
<button ion-button (click)="remove(i);">Delete</button>
Run Code Online (Sandbox Code Playgroud)
在我的.ts中,我有以下代码:
this.items = [
{user: 'UserA'},
{user: 'UserB'}
];
remove(no) {
(this.items).splice(no, 1);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,现在,当用户单击按钮时,顶部打开弹出窗口的方法称为:
<button ion-button (click)="showConfirmAlert();">Delete</button>
Run Code Online (Sandbox Code Playgroud)
而且我现在不确定如何从列表中删除该项目。
showConfirmAlert() {
let alert = this.alertCtrl.create({
title: 'Confirm delete user',
message: 'Are you sure you want to permanently delete this user?',
buttons: [
{
text: 'No',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'Yes',
handler: () => {
}
}
]
})
}
Run Code Online (Sandbox Code Playgroud)
我是否需要在showConfirmAlert方法内编写一个单独的remove函数?我该怎么做呢?抱歉,这里很新,任何帮助将不胜感激!
直到最近我开始遇到插件问题,该插件才能正常工作,该代码无法执行,也不会引发错误。我想从相机捕获图像并将base64字符串发送到服务器,这很容易,因为我可以直接获取base64捕获图像的图像,但是随后我使用了本地作物,该作物返回了URI图像的图像。因此,现在我必须获取base64此图片的,但是该Base64插件不再起作用。任何解决方法或帮助都非常感谢。我使用的代码:
this.base64.encodeFile(filePath).then((base64File: string) => {
console.log(base64File); // Won't execute
}, (err) => {
console.log(err); // Won't execute
});
Run Code Online (Sandbox Code Playgroud) 无论如何,在Ionic 3中使用警报显示新行吗?
我应该用'\ n'代替什么?
doFinalise() {
let confirm = this.alertCtrl.create({
title: 'Are you sure?',
message: 'Are these details correct?\n Price ($/L): \n KMs Done: \n Total Spent: \n Fuel Type: \n Date: ',
buttons: [ etc...
Run Code Online (Sandbox Code Playgroud)
最终,该消息将在新行之前显示变量,但是在此阶段不需要。
我正在尝试从主网站上实例化一个angular-google-maps示例:https://angular-maps.com/guides/getting-started/来对应用程序进行一些测试.
我使用了他们的示例代码,如下所示:
import { Component } from '@angular/core';
@Component({
selector: 'page-location',
templateUrl: 'location.html',
})
export class LocationPage {
title: string = 'My first AGM project';
lat: number = 51.678418;
lng: number = 7.809007;
}
page-location
{
agm-map {
height: 150px;
}
}
<h1>{{ title }}</h1>
<!-- this creates a google map on the page with the given lat/lng from -->
<!-- the component as the initial center of the map: -->
<agm-map style="height: 300px;" [latitude]="lat" [longitude]="lng"> …Run Code Online (Sandbox Code Playgroud)