标签: nativescript

在 nativesscript 中的路由之间传递参数

在 NativeScript 应用程序中,我有两条路线如下:

{ path : "boxes" , component : BoxesPage } ,
{ path : "card" , component : CardPage } ,
Run Code Online (Sandbox Code Playgroud)

在 BoxesPage 中,我试图像这样将一些东西传递给 CardPage:

constructor ( private _routerExtention : RouterExtensions , private _router : Router) {
    }

onItemTap ( _box ) {
        let navigationExtras : NavigationExtras = {
            queryParams : { 'box' : _box } ,
            fragment    : 'anchor'
        };
        this._router.navigate( [ '/card' ] , navigationExtras );
    }
Run Code Online (Sandbox Code Playgroud)

然后在 CardPage 组件中:

 ngOnInit () : any {
        this.route.params.subscribe( …
Run Code Online (Sandbox Code Playgroud)

nativescript angular2-nativescript

3
推荐指数
1
解决办法
3630
查看次数

NativeScript Angular ListView 渲染 [object Object]

我正在尝试在 Nativescript + Angular 中播放 ListView,但无法呈现定义的模板。我的 ListView 显示的是 [object Object] 而不是模板。我总是得到那个结果。如果数组中的项是字符串,则文本显示在行上,如果是对象,则坚持不显示我的模板并显示 [对象对象]。

我得到的结果是这样的:

在此处输入图片说明

下面是我的代码

eventos.component.ts

import {Component, OnInit, ChangeDetectionStrategy, Input} from '@angular/core';


@Component({
  selector: "PrincipalEventosListView",
  templateUrl: "pages/principal/eventos/eventos.component.html",
  changeDetection: ChangeDetectionStrategy.OnPush,
})

export class PrincipalEventosComponent  {

  public registros: Array<any>;

    constructor() {

        this.registros = [];
        this.registros.push({tipo: "Teste 1"});
        this.registros.push("String no lugar de objeto.");
        this.registros.push({tipo: "Teste 3"});
        this.registros.push(123);
        this.registros.push({tipo: "Teste 4"});
    }

}
Run Code Online (Sandbox Code Playgroud)

eventos.component.html

<GridLayout>

<ListView [items]="registros">
    <template let-item="item">
        <Label [text]="item.tipo"></Label>
    </template>
</ListView>
Run Code Online (Sandbox Code Playgroud)

nativescript angular2-nativescript angular

3
推荐指数
1
解决办法
1678
查看次数

找不到模块“应用程序设置”

尝试包含“应用程序设置模块”时出现错误。

*找不到模块“应用程序设置”<-----错误

错误在我的 storage.driver.ts 中,它位于使用环回 sdk 构建器构建的 nativescript sdk 中

storage.driver.ts

import * as AppSettings from 'application-settings'; <---- Error here
export class StorageDriver {
static set(key: string, value: any) {
AppSettings.setString(key, String(value));
}
static get(key: string): any {
return AppSettings.getString(key);
}
static remove(key: string): any {
if (AppSettings.hasKey(key)) {
  AppSettings.remove(key);
} else {
  console.log('Trying to remove unexisting key: ', key);
}
}
}
Run Code Online (Sandbox Code Playgroud)

我应该怎么做才能解决这个问题?我是 nativescript 的新手。

typescript nativescript angular

3
推荐指数
2
解决办法
2338
查看次数

如何为 NativeScript 的 FlexboxLayout 中插入和删除的元素设置动画?

我试图让一行按钮根据是否添加或删除其他按钮而增长和缩小。FlexboxLayout似乎最适合这项工作,但除了手动操作一段时间的宽度百分比之外,我似乎无法弄清楚如何解决这个问题。

我想我可以设置flexGrow它们,然后使用一个类visibility: collapse来基本上删除按钮。(然后在恢复正常时反转。)这有效,但变化非常瞬时。我想要某种挤压/拉伸动画。

我尝试玩动画,将比例缩小到 0,如下所示。虽然按钮似乎缩小了,但它只向自身中心收缩,并且仍然保持它占据的空间(留下一个间隙)。

我正在玩这样一个简单的例子:

<FlexboxLayout flexDirection="row">
  <Button text="1" width="25%" flexGrow="1"></Button>
  <Button text="2" width="25%" id="test-button"></Button>
  <Button text="3" width="25%" flexGrow="1"></Button>
  <Button text="4" width="25%" flexGrow="1"></Button>
</FlexboxLayout>
Run Code Online (Sandbox Code Playgroud)

我尝试做这样的事情,我想缩小按钮 #2 消失:

let testButton = this.page.getViewById("test-button");
testButton.animate({
  scale: { x: 0, y: 1},
  duration: 500
});
Run Code Online (Sandbox Code Playgroud)

我也尝试用关键帧来做到这一点。那似乎什么也没做。

#test-button {
  animation-name: shrink;
  animation-duration: 2s;
  animation-delay: 1s;
}


@keyframes shrink {
    from { width: 25%; }
    to { width: 0; }
}
Run Code Online (Sandbox Code Playgroud)

我试图为网页做一些类似于这个答案中提到的事情,但这似乎也没有做任何事情。

我设法通过使用手动调整宽度的数据绑定使其工作setTimeout。但我想知道是否可能有其他更容易管理的路线?不禁想知道我是否在其他尝试中搞砸了一些东西。

nativescript angular2-nativescript

3
推荐指数
1
解决办法
1285
查看次数

Angular2/Nativescript:在软键盘上按下返回键时提交表单

我有一个带有用户名和密码 TextFields 的 Angular2/Nativescript 登录组件...当编辑密码 textField 时,我将 returnKeyType 设置为“done”,并期望在软键盘上按下 Done 时调用 login() 函数。在按下完成键的那一刻,键盘被解除,但登录功能没有被调用,所以我仍然需要在键盘被解除后点击登录按钮才能提交表单。当在 Nativescript 中的特定 TextField 上按下返回键时,有什么方法可以提交表单?如果是这样,我该如何实施它?我尝试了 returnPress 事件,但没有任何反应......

我的代码:

<ActionBar title="Login"></ActionBar>
<StackLayout class="page">
    <GridLayout columns="*, auto" rows="auto">
        <ActivityIndicator class="m-l-10 m-t-10 activity-indicator" [busy]="busy" [visibility]="busy ? 'visible' : 'collapse'" horizontalAlignment="left"></ActivityIndicator>
        <Button row="0" col="1" id="setIPBtn" class=" m-t-20 pull-right font-awesome" text="&#xf0ad; Settings" (tap)="setIP()"></Button>
    </GridLayout>

    <Label class="m-x-auto m-t-20 title h1 text-primary p-x-10" text="Log In" backgroundColor="blue"></Label>
    <StackLayout class="form">
        <StackLayout class="input-field">
            <Label class="body label text-left" text="Enter Username"></Label>
            <TextField class="input input-border" hint="Username" [(ngModel)]="username" autocorrect="false" autocapitalizationType="none" returnKeyType="next"></TextField>
        </StackLayout> …
Run Code Online (Sandbox Code Playgroud)

nativescript angular2-nativescript angular

3
推荐指数
1
解决办法
1013
查看次数

Store 没有提供者!注射错误Error

应用程序组件.html

<page-router-outlet></page-router-outlet>
Run Code Online (Sandbox Code Playgroud)

app.component.ts

import 'rxjs/add/operator/let';
import { Component, ViewEncapsulation } from '@angular/core';
import { EchoesState, getSidebarCollapsed$ } from './core/store';
import { Store } from '@ngrx/store';

@Component({
   selector: "ns-app",
   templateUrl: "app.component.html",
})
export class AppComponent {
  constructor(private store: Store<EchoesState>){}
}
Run Code Online (Sandbox Code Playgroud)

app.module.ts

import 'nativescript-localstorage';
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";

import { NativeScriptRouterModule } from "nativescript-angular/router";
import { NativeScriptFormsModule } from "nativescript-angular/forms";

import { AppRoutingModule } from "./app.routing";
import { AppComponent } from "./app.component";

import …
Run Code Online (Sandbox Code Playgroud)

nativescript ngrx angular2-nativescript ngrx-store angular-nativescript

3
推荐指数
1
解决办法
6372
查看次数

NativeScript StackLayout 子元素之间有间隙

我正在使用 NativeScript StackLayout 组件来布局我的元素。

在 StackLayout 的子元素之间创建间隙的最佳方法是什么?

nativescript

3
推荐指数
1
解决办法
2443
查看次数

References.d.ts 文件有什么作用?它在 NativeScript 项目中的位置是什么?

我正在使用 nativescript关注本教程,它声明要放置

/// <reference path="./node_modules/nativescript-barcodescanner/barcodescanner.d.ts" /> Needed for autocompletion and compilation.

在 references.d.ts 中。我的问题是这个文件有什么作用以及它在 nativescript 应用程序中的位置

javascript typescript nativescript

3
推荐指数
1
解决办法
3464
查看次数

使用本机脚本在Android应用程序中加载页面时如何显示键盘?

我的 android 应用程序的第一页有一个输入字段。所以我想要的是当这个页面加载时我想自动显示键盘而不点击输入字段。

android nativescript

3
推荐指数
1
解决办法
2309
查看次数

NativeScript-无法在单个dex文件中容纳请求的类

我正在使用将最新版本的NativeScript与Angular结合使用的应用程序。我已将大多数pro-ui插件添加到我的项目中,并添加了Firbase插件。

当我运行“ tns run android”时,出现错误:

“ D8:无法在单个dex文件中容纳请求的类。尝试提供主要索引列表。”

此外,它花费了5分钟以上的时间来构建。我一直在进行搜索,但是找不到导致此问题的原因。有人知道哪里出问题了吗?

android nativescript

3
推荐指数
1
解决办法
465
查看次数