我正在实施离子应用程序的单元测试,需要检查$ rootScope上没有广播任何事件
expect($rootScope.$broadcast).not.toHaveBeenCalled();
Run Code Online (Sandbox Code Playgroud)
问题是有时会广播$ locationChangeStart和$ locationChangeSuccess事件,这会使我的测试失败.似乎离子v1.3.0触发了以下代码中的那些
// update browser
$rootScope.$watch(function $locationWatch() {
var oldUrl = trimEmptyHash($browser.url());
var newUrl = trimEmptyHash($location.absUrl());
var oldState = $browser.state();
var currentReplace = $location.$$replace;
var urlOrStateChanged = oldUrl !== newUrl ||
($location.$$html5 && $sniffer.history && oldState !== $location.$$state);
if (initializing || urlOrStateChanged) {
initializing = false;
$rootScope.$evalAsync(function() {
var newUrl = $location.absUrl();
var defaultPrevented = $rootScope.$broadcast('$locationChangeStart', newUrl, oldUrl,
$location.$$state, oldState).defaultPrevented;
Run Code Online (Sandbox Code Playgroud)
上面的代码中的"初始化"标志为true,这会触发$ rootScope.$ broadcast.问题 - 为什么会这样?处理这种情况的最佳方法是什么?现在我添加了$ rootScope.$ digest(); 在我的测试中表现出来似乎解决了问题,但我不确定这是否是有效的解决方案
谢谢
我在使用这些代码时遇到麻烦,我在以下代码块中创建了标题
headers.append("Authorization",btoa(username+":"+password));
var requestOptions = new RequestOptions({headers:headers});
Run Code Online (Sandbox Code Playgroud)
但是如果我尝试在post方法中使用它
return this.http.post(url,JSON.stringify({username,password}),requestOptions)
.map(res=>res.json())
.map(res=>{
if(res){
localStorage.setItem("isLogged",res);
this.loggedIn =true;
}
return res;
});
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息
Typescript Error
Argument of type 'RequestOptions' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'. Types of property 'headers' are incompatible. Type 'Headers' is not assignable to type 'HttpHeaders | { [header: string]: string | string[]; }'. Type 'Headers' is not assignable to type '{ [header: …Run Code Online (Sandbox Code Playgroud) 我是ionic3的新手,我有2页,一个是列表页面,有上市,我从Rest API获取该列表,当我点击该列表中的特定项目,那时我想获得该页面的详细信息,但是当我点击特定项目时我收到错误:ListDetailsPage is part of the declaration of 2 modules, Please consider moving ListDetailsPage to a higher module that imports AppModule and ListDetailsPageModule,有谁可以请帮助我为什么我收到此错误?在这里,我添加了我的所有代码,
1)app.module.ts
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { AboutPage } from '../pages/about/about';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { ListPage } from '../pages/list/list';
import { ListDetailsPage …Run Code Online (Sandbox Code Playgroud) 在我的Ionic应用程序上遇到一个奇怪的问题,我昨天能够构建得很好但是在一个构建版本中它下载了一堆像构建android时那样的文件然后我收到了以下错误:
找不到support-vector-drawable.aar(com.android.support:support-vector-drawable:27.1.1).在以下位置搜索:https: //jcenter.bintray.com/com/android/support/support-vector-drawable/27.1.1/support-vector-drawable-27.1.1.aar
在链接后https://jcenter.bintray.com/com/android/support/support-vector-drawable/27.1.1/support-vector-drawable-27.1.1.aar,页面具有以下JSON:
{
"errors": [
{
"status": 404,
"message": "Could not find resource"
}
]
}
Run Code Online (Sandbox Code Playgroud) 也许我缺少了一些东西,但是我以前访问过的离子缓存视图遇到了问题,阻止了Angular重新初始化组件。从某些缓存中提取组件,并将其呈现为以前存在的任何数据。
范例:
用户A登录到应用程序中,并在“主页”页面上开始显示与用户A相关的信息。用户A注销并导航到“登录”。
用户B从相同的应用程序登录并导航到“主页”页面。Ionic看到用户先前曾访问过Home(用户A),而不是实例化“ Home”,而是从缓存中提取视图,并显示用户A所捕获的所有内容。
我注意到ion-router-outlet在导航时添加了页面过渡,并且当导航进行“前进”时,该过渡向左交换,而在导航进行“后退”时向右滑动。该数据似乎是从存储缓存视图的同一历史源读取的。
TL; DR如何控制离子路由器历史记录(URL树),以防止视图缓存以防止角度重新初始化组件?
我将Angular更新为版本8,但遇到一个小问题。当我用离子发球启动应用程序时
Error: Can't resolve all parameters for setupPlatform: (?, [object
Object], [object Object]).
at syntaxError (http://localhost:8100/build/vendor.js:177346:17)
at CompileMetadataResolver._getDependenciesMetadata
(http://localhost:8100/build/vendor.js:196072:35)
at CompileMetadataResolver._getFactoryMetadata
(http://localhost:8100/build/vendor.js:195972:51)
at CompileMetadataResolver.getProviderMetadata
(http://localhost:8100/build/vendor.js:196204:43)
at http://localhost:8100/build/vendor.js:196134:49
at Array.forEach (<anonymous>)
at CompileMetadataResolver._getProvidersMetadata
(http://localhost:8100/build/vendor.js:196094:19)
at http://localhost:8100/build/vendor.js:195717:119
at Array.forEach (<anonymous>)
at CompileMetadataResolver.getNgModuleMetadata
(http://localhost:8100/build/vendor.js:195708:49)
Run Code Online (Sandbox Code Playgroud)
我试图回滚到旧版本,仍然遇到相同的问题。我有另一个离子应用程序,它可以与我的配置一起使用。
配置为:
Ionic:
Ionic CLI : 5.2.1
Ionic Framework : ionic-angular 3.9.6
@ionic/app-scripts : 3.2.4
Cordova:
Cordova CLI : 6.5.0
Cordova Platforms : android 6.1.2, browser 4.1.0, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-webview 1.2.1, (and 16 other plugins)
Utility: …Run Code Online (Sandbox Code Playgroud) 我确实使用ionic 4构建。
离子科尔多瓦建立Android
得到这个错误
科尔多瓦建立Android
源路径不存在:resources / android / xml / network_security_config.xml [错误]运行子进程cordova时发生错误。
我从config.xml中删除了这部分。可以吗
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:networkSecurityConfig="@xml/network_security_config" />
</edit-config>
<resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
Run Code Online (Sandbox Code Playgroud)
package.json
{
"name": "morenito",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~8.0.1",
"@angular/cdk": "8.0.1",
"@angular/material": "8.0.1",
"@angular/common": "~8.1.2",
"@angular/compiler": "~8.1.2",
"@angular/core": "~8.1.2",
"@angular/forms": "~8.1.2",
"@angular/http": "^7.2.2",
"@angular/platform-browser": "~8.1.2", …Run Code Online (Sandbox Code Playgroud) 有没有办法使用$ ionicHistory.goBack(-2)更改我要返回的状态的$ stateParams?
我正在使用Ionic开发一个小应用程序,但我面临以下问题:
我有几个状态是整个过程的一部分:productInfo,选择和比较.用户选择产品,然后其信息显示在productInfo状态中.所选产品通过$stateParams.
productInfo状态
$stateProvider.state('productInfo', {
url: '/compare/info',
params: {
product: null
},
cache: false,
views: {
'main-screen': {
templateUrl: 'templates/modules/comparator/info.html',
controller: 'CompareInfoCtrl',
controllerAs: 'product'
}
}
})
Run Code Online (Sandbox Code Playgroud)
在productInfo内部,有一个比较按钮,用户进行选择,并选择另一个产品与第一个产品进行比较.
当用户在选择状态下确认他的选择时,应用程序进入最后状态,即比较,显示两个产品的结果.
在最后一个状态(比较)中,如果用户单击其中一个产品,则应用程序必须返回状态1,productInfo,并选择所单击的产品.
我正在使用$ionicHistory.goBack(-2)而不是$state.go('productInfo')避免弄乱我的后退按钮(每个屏幕都有一个默认按钮,它只是调用$ ionicHistory.goBack()).
问题出现了:我无法更改$stateParamsproductInfo状态,因此显示了最后选择的产品.
理想情况就是这样$ionicHistory.goBack(-2, {product: obj}).
我的最后一枪是:
this.$ionicHistory.viewHistory().views[this.$ionicHistory.backView().backViewId].stateParams.id = this.selectedProduct.id;
this.$ionicHistory.goBack(-2);
Run Code Online (Sandbox Code Playgroud)
但这会创造一个新的历史,因此无法按预期工作.
我在离子项目中使用离子标签,但描述没有显示(而是显示点点.. ..)我希望它显示整个文本..有什么解决方案吗?
<ion-card *ngFor="let product of products">
<img [src]="product.imageURL" />
<ion-card-content>
<ion-card-title primary [innerHTML]="product.title"></ion-card-title>
<ion-item class="item-text-wrap">
<ion-item>
<ion-label primary>Description</ion-label>
<ion-label [innerHTML]="product.description"></ion-label>
</ion-item>
</ion-card-content>
</ion-card>
Run Code Online (Sandbox Code Playgroud)
我对Typescript和Ionic 2很新,我试图通过Ionic 2搜索栏过滤json响应.
这是我的代码:
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import {Http} from '@angular/http';
import 'rxjs/add/operator/map';
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
posts: any;
private searchQuery: string = '';
private items: string[];
constructor(private http: Http) {
this.initializeItems();
this.http.get('https://domain.co/open.jsonp').map(res => res.json()).subscribe(data => {
this.posts = data;
console.log(this.posts);
});
}
initializeItems() {
this.items = this.posts;
}
getItems(ev: any) {
// Reset items back to all of the items
this.initializeItems();
// set val to the value of the searchbar …Run Code Online (Sandbox Code Playgroud) ionic-framework ×10
angular ×6
ionic3 ×4
typescript ×4
angularjs ×2
ionic2 ×2
android ×1
cordova ×1
ionic-native ×1
ionic4 ×1
jasmine ×1
javascript ×1
unit-testing ×1