标签: nativescript

fetch Promise 永远不会被执行

我正在使用 nativescript 为 android 开发应用程序。我有类似的东西

var fetchModule = require("fetch");
fetchModule.fetch("http://202.120.227.11/")
    .then(function(resp){
        console.log(JSON.stringify(resp));
        return resp;
    })
    .catch(function(err){
        console.log(JSON.stringify(err));
        return err;
    });
Run Code Online (Sandbox Code Playgroud)

then块永远不会被执行。有时catch块被执行并给出网络错误。但无论哪种情况,根据我的 tcpdump 记录,请求被发送并顺利收到响应。

因此,似乎 nativescript 出于某种原因过滤了响应。

有人经历过吗?

promise nativescript fetch-api

4
推荐指数
1
解决办法
688
查看次数

如何让 NativeScript 在其本机邮件客户端中打开电子邮件标签?

我有一个简单的页面/屏幕。我希望能够在设备上打开本机邮件客户端时单击标签上的电子邮件地址。(即mailto:等效)。

我目前只关心 iOS。

这可能吗?

XML

<Page loaded="pageloaded">
    <GridLayout>
        <StackLayout>
            <Label text="sometest.mail@gmail.com">         
        </StackLayout>
    </GridLayout>
</Page>
Run Code Online (Sandbox Code Playgroud)

email email-client nativescript

4
推荐指数
1
解决办法
2525
查看次数

ngOnInit 直到我导航到另一个组件后才运行

在我的 NativeScript 应用程序中,我将路由设置为

export const routes = [
    { path: "",  component: AppComponent},
    { path: "home", component: HomeComponent},
    { path: "login", component: LoginComponent},
    { path: "news" , component: NewsComponent}
];
Run Code Online (Sandbox Code Playgroud)

用户通过 firebase 登录后,用户会自动重定向到HomeComponent. 我应该提一下,我有一个用户服务,它从AppComponent Constuctor确定用户是否已经登录然后将他们重定向到登录或主页中被触发。

我将 console.log() 分布在整个组件中,以查看触发事件的时间,以便我可以尝试找出代码的放置位置。

import {Component, OnInit} from "@angular/core";
import {Page} from "ui/page";
import {RouterExtensions} from 'nativescript-angular/router';
import firebase = require("nativescript-plugin-firebase");

@Component ({
    selector : "home",
    templateUrl: "./pages/home/home.html",
    styleUrls: ["./pages/home/home.css"]
})
export class HomeComponent implements OnInit {

    private router;

    constructor(page: Page, router: …
Run Code Online (Sandbox Code Playgroud)

nativescript angular2-nativescript

4
推荐指数
1
解决办法
1756
查看次数

由 ScrollView 包装的 Nativescript GridLayout

我有一个定义如下的 nativescript xml 视图:

<Page 
 xmlns="http://schemas.nativescript.org/tns.xsd"
 xmlns:menu="components/menu"
 xmlns:header="components/header" 
 loaded="loaded">
<header:header />
<StackLayout orientation="vertical">
<ScrollView>
    <GridLayout rows="auto,auto,auto,auto" cols="auto,auto" >
        <Image      row="0" colSpan="2" src="~/img/tap.png" tap="takePicture"/>
        ...
        <TextField  row="2" col="1" horizontalAlignment="right" />
        <Button     row="3" colSpan="2" text="UPLOAD" />
    </GridLayout>
</ScrollView>
<menu:menu />
</StackLayout>
</Page>
Run Code Online (Sandbox Code Playgroud)

GridLayout 太大而无法包含在单个屏幕中,因此我将其包裹在 ScrollView 中。然而,这不起作用:我无法滚动页面,因此无法访问最后的 UI 元素,如 TextField 和 Button。我究竟做错了什么?我应该在不同的位置插入 ScrollView 标签吗?

xml nativescript

4
推荐指数
1
解决办法
2120
查看次数

NativeScript / Angular Page.getViewById 返回“未定义”

我正在开发 NativeScript/Angular 应用程序。我是 NativeScript 的新手,正在学习基于早期版本的教程(我的是 4.1.0,不确定他们在使用什么)。有一个带有 DatePicker 元素的模式对话框。我希望它将所选日期返回给父元素。该应用程序编译并启动得很好。但是,当我尝试打开模态时,出现错误“无法设置未定义的‘年份’属性”。

HTML如下:

<StackLayout class="modal-view-style">
  <StackLayout>
    <DatePicker id="datePicker"></DatePicker>
  </StackLayout>
  <Button class="btn btn-primary btn-active" text="submit" (tap)="submit()"></Button>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)

这是课程:

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { ModalDialogParams } from 'nativescript-angular/modal-dialog';
import { DatePicker } from 'tns-core-modules/ui/date-picker';
import { Page } from 'tns-core-modules/ui/page';

@Component({
  moduleId: module.id,
  templateUrl: './date-picker-modal.component.html'
})
export class DatePickerModalComponent implements OnInit {

  constructor(private params: ModalDialogParams, private page: Page) { }

  ngOnInit() { 
    let datePicker: DatePicker = <DatePicker>this.page.getViewById<DatePicker>('datePicker');

      let currentdate: Date …
Run Code Online (Sandbox Code Playgroud)

nativescript angular2-nativescript angular

4
推荐指数
1
解决办法
3784
查看次数

如何在 NativeScript &lt;Button&gt; 中使用字体图标

尝试在<Button>.

例如:

<Button class="btn btn-primary fas" text="{{'fa-film' | fonticon}} Test"></Button>
Run Code Online (Sandbox Code Playgroud)

CSS:

.fas {
  font-family: 'Font Awesome 5 Free Solid', fa-solid-900;
}
Run Code Online (Sandbox Code Playgroud)

当使用Nativescript主题,它定义font-family.btn类。如您所知,iconfonts 也依赖于此font-family

那么在上面的按钮中,如何将一个font-family应用于字符串 Test 而将另一个font-family应用于图标?

如果您使用 NativeScript Angular SASS 入门应用程序并在其中定义 .fas_app-common.scss并使用我上面的按钮,您将看到图标显示为 ?。这是因为.btn覆盖了font-family.

我可以通过为图标font-family提供更高的优先级来解决这个问题- 但这会阻止我为按钮上的文本字体设置样式。

按钮内字体图标的非原生脚本实现通过将元素(如<span>)作为子元素放置到<Button>. 示例在这里

你怎么能用 NativeScript 做到这一点<Button>

nativescript angular2-nativescript

4
推荐指数
1
解决办法
1812
查看次数

任务的 NativeScript 执行失败:合并 dex 档案时出错

在构建 NS + Vue 应用程序时,出现以下错误 -

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives
Run Code Online (Sandbox Code Playgroud)

错误是因为 .dex 文件中的方法引用数不能超过 64K。错误也指向https://developer.android.com/tools/building/multidex.html上的解决方案

该解决方案建议启用应用multidex超过64K的方法,即添加multiDexEnabled truebuild.gradle其中解决了错误。

在NativeScriptbuild.gradle位于platforms/,所以每当我清理与平台tns platform clean或删除platforms/,我不得不再次添加multiDexEnabled truebuild.gradle

有没有永久的解决方案?

android build gradle vue.js nativescript

4
推荐指数
1
解决办法
770
查看次数

从android拉取Sqlite数据库给出空数据库

我正在开发一个使用 Sqlite 的移动应用程序,我想从手机中提取 .db 文件并在 Sqlite 的数据库浏览器中查看它。

问题来自这样一个事实,即当我运行 adb 命令时,我得到的 .db 文件是空的,即使我已经创建了表并将数据添加到数据库中的这些表中。

在应用程序中,我查询数据库中插入的记录并返回它们。有什么想法吗?

adb 命令: adb exec-out run-as projectname cat databases/my.db > my.db

数据库创建代码:

if(!Sqlite.exists("my.db")){
        new Sqlite("my.db")
        .then(
            (db) => {
            //create table here
                db.execSQL("CREATE TABLE IF NOT EXISTS Times (Id INTEGER PRIMARY KEY AUTOINCREMENT, clockIn TEXT, clockOut TEXT)")
                .then(
                    () => {
                        console.log("succcess")
                        db.execSQL("INSERT INTO Times (clockIn, clockOut) VALUES (?, ?)", ["Nic", "Raboy"]).then(() => {
                            db.all("SELECT * FROM Times").then((rows) => {
                                console.log(rows)
                            })
                        })

                    }, 
                    (error) => { 
                        console.log('Error …
Run Code Online (Sandbox Code Playgroud)

sqlite android nativescript

4
推荐指数
1
解决办法
1429
查看次数

如何在 Nativescript 中获取 elementById?

我正在将 nativescript 与 vue.js 一起使用,并且正在尝试执行诸如 DOM 操作之类的操作。这是我的模板中的示例代码:

<Label textWrap="true">
    <FormattedString id="formString"
      backgroundColor="yellow"
      effectiveHeight="100"
      effectiveWidth="100%">
      <Span text="This text has a " /> 
    </FormattedString>
 </Label>
Run Code Online (Sandbox Code Playgroud)

我想通过他的 id获取标签元素FormattedString - formString 在 javascript 中是这样的:

let fs = doument.getElementById('formString');
我怎样才能在 Nativescript-Vue 中做到这一点?我知道有库nativescript-dom,但我不想将整个库用于简单的 getById。

javascript vue.js nativescript nativescript-vue

4
推荐指数
1
解决办法
3150
查看次数

如何在没有 Nativescript 的 Actionbar 的情况下更改 IOS 中的状态栏颜色?

如果不需要 ActionBar / NavigationBar,我无法弄清楚如何在 nativescript 中更改 IOS 的状态栏。

我试过了:

var navController = frame.topmost().ios.controller;
let navigationBar = navController.navigationBar;
navigationBar.barStyle = UIBarStyle.Black;
Run Code Online (Sandbox Code Playgroud)

但是当没有 ActionBar 时,这完全失败了!

nativescript

4
推荐指数
1
解决办法
499
查看次数