我在一个真实的项目中有一个真实的场景,我需要2个服务来访问彼此的属性和/或方法.我不是Angular专家所以它可能吗?
我试过了,它失败了.这是我的尝试:
app.component.ts
import { Component } from '@angular/core';
import { FirstService } from './first.service';
import { SecondService } from './second.service';
@Component({
selector: 'my-app',
template: '<h1>Hello world!</h1>',
providers: [FirstService, SecondService]
})
export class AppComponent {
constructor(public firstService: FirstService, public secondService: SecondService) {
console.log(firstService.foo);
console.log(secondService.bar);
}
}
Run Code Online (Sandbox Code Playgroud)
first.service.ts
import { Injectable } from '@angular/core';
import { SecondService } from './second.service';
@Injectable()
export class FirstService {
foo: string = 'abc';
constructor(public secondService: SecondService) {
this.foo = this.foo + this.secondService.bar;
}
}
Run Code Online (Sandbox Code Playgroud)
second.service.ts …
自从更新到RC.0以来,我遇到了与moment.js(我通过npm安装)相关的构建错误:
[13:44:16] Error: Cannot call a namespace ('moment')
Run Code Online (Sandbox Code Playgroud)
我试过两种方式来引用时刻:
import * as moment from 'moment';import moment from 'moment'错误是一样的.
问)我做错了什么?这在RC.0之前有效
我按照文档说明将Ionic从RC1更新到RC3,之后我无法在Android中使用ionic run android或正确运行我的应用程序ionic build android.使用ionic serve和.apk构建预览可以正常工作,但是当我在我的设备或模拟器中运行应用程序时,它会显示启动画面并显示空白的WebView.当我调试via时chrome://inspect,它在控制台中显示以下错误:
main.js:7 Uncaught Error: Cannot find module "./app.module.ngfactory"
Run Code Online (Sandbox Code Playgroud)
我更新,之前所做的项目文件夹的备份,当我的应用程序工作正常,并且代码是相同的(在升级过程中没有变化),而且app.module.ts,main.dev.ts和main.prod.ts似乎罚款.我尝试删除.tmp和node-modules文件夹并npm install再次运行,但错误仍然存在.
所以我是Ionic的新手,可能会遗漏一些东西.但我开始这样一个新的空白应用程序:
ionic start BlankApp --v2 blank
然后添加了浏览器平台:
cordova platform add browser
然后为生产而建造:
ionic build browser
输出如下所示:
> ionic-hello-world@ ionic:build C:\Work\ionic\BlankApp
> ionic-app-scripts build
keywords if/then/else require v5 option
[17:56:25] ionic-app-scripts 0.0.47
[17:56:25] build dev started ...
[17:56:25] clean started ...
[17:56:25] clean finished in 3 ms
[17:56:25] copy started ...
[17:56:25] transpile started ...
[17:56:28] transpile finished in 3.47 s
[17:56:28] webpack started ...
[17:56:28] copy finished in 3.65 s
[17:56:34] webpack finished in 5.65 s
[17:56:34] sass started ... …Run Code Online (Sandbox Code Playgroud) 如何在离子v2的标题中插入徽标?
<ion-header>
<ion-navbar>
<ion-title></ion-title>
</ion-navbar>
</ion-header>
Run Code Online (Sandbox Code Playgroud) 我正在开发Ionic 3.2版本的应用程序.我在离子卷轴内有一个离子复习器.我想禁用滚动,ion-content并希望在滚动时显示ion-refresher内部.但它失败了.ion-scrollion-list
no-bounce(<ion-content no-bounce>)和disable-scroll(<ion-content disable-scroll>)但内容仍在滚动ion-fixed内部content和内部放在div正下方content.但后来ion-refresher不行.scroll="false"(比如在离子1.0中)但仍在滚动代码下方;
<ion-content scroll="false">
<ion-scroll scrollY="true" style="width: 100% !important;height:30% !important">
<ion-refresher (ionRefresh)="fill_data($event)">
<ion-refresher-content pullingIcon="arrow-dropdown" pullingText="{{ 'pull_to_refresh' | translate }}" refreshingSpinner="circles"
refreshingText="{{ 'refreshing' | translate }}">
</ion-refresher-content>
</ion-refresher>
<ion-list>
//data filling here
</ion-list>
</ion-scroll>
</ion-content>
Run Code Online (Sandbox Code Playgroud)
请帮我...
我有一个搜索栏,我检查输入事件,然后筛选firebase数据.
这是html代码:
<ion-searchbar (ionInput)="getItems($event)" placeholder="Add tag ... "></ion-searchbar>
<ion-list>
<ion-item *ngFor="let tag of tagList">
<h2> {{ tag.name }} </h2>
</ion-item>
</ion-list>
Run Code Online (Sandbox Code Playgroud)
这是ts代码:
getItems(searchbar) {
// Reset items back to all of the items
this.initializeItems();
// set q to the value of the searchbar
var q = searchbar.srcElement.value;
// if the value is an empty string don't filter the items
if (!q) {
return;
}
this.tagList = this.tagList.filter((v) => {
if(v.name && q) {
if (v.name.toLowerCase().indexOf(q.toLowerCase()) > -1) {
return true; …Run Code Online (Sandbox Code Playgroud) 你能告诉我下面两种方法的区别是什么吗?我应该在哪一刻使用它?
book.ts
this.app.getRootNav().push('FromBook', { bookId: this.data.id })
this.navCtrl.push('FromBook', { bookId: this.data.id });
Run Code Online (Sandbox Code Playgroud)
当我们使用下面的内部组件时,它有时会起作用.有时它不是.为什么这种不同的行为有上述2种导航方法?
笔者-page.html中
<div>
<book *ngFor="let book of authorData?.books" [data]="book"></book>
</div>
Run Code Online (Sandbox Code Playgroud) 我正在使用离子3.
这是我的模板
<ion-slides autoplay="5000" loop="true" speed="500" class="slides" pager="true">
<ion-slide *ngFor="let Image of PImage">
<img src="{{Image.URL}}" alt="Product Image">
</ion-slide>
</ion-slides>
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误
TypeError: Cannot read property 'hasAttribute' of undefined
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
请告诉我,
谢谢
我在离子中创建输入,只接受数字.这适用于除safari和ipad之外的所有浏览器和设备.我不希望用户比其他numbers.I输入任何试图做的输入事件正则表达式验证,但不从字母打字停止用户.我尝试了keydown事件,但我没有得到keyDown事件的innerText.请帮忙
ionic2 ×10
typescript ×6
angular ×5
ionic3 ×4
cordova ×2
npm ×2
android ×1
angularjs ×1
browser ×1
build ×1
ecmascript-6 ×1
ipad ×1
javascript ×1
momentjs ×1
safari ×1