我有一个可以在 Angular 2 中工作的代码,但是当我尝试在 NativeScript 项目中使用它时失败了。\nI\xc2\xb4m 试图拒绝这样的承诺:
\n\nlogin(credentials:Credentials):Promise<User> {\n if (!valid) {\n return Promise.reject<User>("Invalid password");\n }else {\n return Promise.resolve(new User("some user"));\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我收到此错误:
\n\nError:(32, 22) TS2346: Supplied parameters do not match any signature of call target.\nRun Code Online (Sandbox Code Playgroud)\n javascript typescript nativescript angular2-nativescript angular
我熟悉 Angular,但我才刚刚开始学习 NativeScript。我有一个使用 NativeScript 库中的 Tab 模板的 Tab 界面。我想在我的选项卡被选中时运行一个函数,但我无法弄清楚。
这是 app.component.html:
<TabView [(ngModel)]="tabSelectedIndex" androidTabsPosition="bottom" (selectedIndexChanged)="onSelectedIndexChanged($event)">
<page-router-outlet *tabItem="{title: 'Home', iconSource: getIconSource('home')}" name="homeTab">
</page-router-outlet>
<page-router-outlet *tabItem="{title: 'Away', iconSource: getIconSource('browse')}" name="awayTab">
</page-router-outlet>
<page-router-outlet *tabItem="{title: 'Matchup', iconSource: getIconSource('search')}" name="matchupTab">
</page-router-outlet>
</TabView>
Run Code Online (Sandbox Code Playgroud)
我还没有真正在 matchup.component.ts 中有任何东西,因为我还没有弄清楚这一点。不过这里是:
import { Component, OnInit } from "@angular/core";
import { DataService } from "../core/data.service";
import { ActivatedRoute } from "@angular/router";
@Component({
selector: "Matchup",
moduleId: module.id,
templateUrl: "./matchup.component.html"
})
export class MatchupComponent implements OnInit {
constructor(
private data: DataService,
private route: ActivatedRoute …Run Code Online (Sandbox Code Playgroud) 我正在尝试显示一个本地 html 文件,其中包含引用的 JS 和 CSS 以及 PNG 图像。我将这些文件放入适用于 Android 的 NativeScript x Angular 应用程序的资产文件夹中。当我运行 tns run android --bundle 并构建应用程序时 - 资产文件夹不包含 html。文件夹结构从 assets > index.html (和 index.html 引用其他文件)。
是否有某个地方或方式我需要包含 html 文件,以便它们包含在构建中?
android nativescript angular2-nativescript nativescript-telerik-ui nativescript-angular
我正在使用NativeScript创建一个示例应用程序.我在Android设备中运行应用程序时遇到模板解析错误.
我在模板中的代码只是:
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
<Page.actionBar>
<ActionBar title="My ActionBar"/>
</Page.actionBar>
</Page>
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Template parse errors:
Only void and foreign elements can be self closed "ActionBar" ("<Page xmlns="http://schemas.nativescript.org/tns.xsd">
<Page.actionBar>
[ERROR ->]<ActionBar title="My ActionBar"/>
</Page.actionBar>
</Page>"): AppComponent@2:6
Error: Template parse errors:
Only void and foreign elements can be self closed "ActionBar" ("<Page xmlns="http://schemas.nativescript.org/tns.xsd">
<Page.actionBar>
[ERROR ->]<ActionBar title="My ActionBar"/>
</Page.actionBar>
</Page>"): AppComponent@2:6
at DirectiveNormalizer.normalizeLoadedTemplate (/data/data/org.nativescript.neurix/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js:13506:21)
at /data/data/org.nativescript.neurix/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js:13499:53
at ZoneDelegate.invoke (/data/data/org.nativescript.neurix/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:190:28)
at Zone.run (/data/data/org.nativescript.neurix/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:83:43)
at /data/data/org.nativescript.neurix/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:449:57
at ZoneDelegate.invokeTask (/data/data/org.nativescript.neurix/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:223:37)
at Zone.runTask (/data/data/org.nativescript.neurix/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:123:47)
at drainMicroTaskQueue (/data/data/org.nativescript.neurix/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:355:35) …Run Code Online (Sandbox Code Playgroud) 我有一个本地脚本角度应用程序,它运行蓝牙服务来连接到外围设备(设备)。该应用程序会显示一个标签,其中包含一条消息,指示尚未将蓝牙设备连接到运行该应用程序的移动设备。我想做的是更新 UI,以便标签在发生连接时消失(并在发生断开连接时重新出现)。
应用程序组件.tns.html
<StackLayout orientation="vertical" marginBottom="50">
<Label text="No bluetooth device detected." id="noBluetoothWarning" horizontalAlignment="center" color="#B11" *ngIf="bluetoothDisconnected" marginTop="30" visibility="{{ isBluetoothConnected ? 'collapsed' : 'visible' }}"></Label>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
应用程序组件.ts
export class NSAppComponent extends AppComponent implements OnInit {
pageData: Observable;
ngOnInit() {
this.bluetoothDisconnected = true;
let _page = <Page>topmost().currentPage;
_page.actionBarHidden = true;
_page.frame.bindingContext = this.pageData;
let that = this;
this.bluetoothScanner.connectionStateChangeEvent.subscribe((connectionState) => {
that.log.debug(`Am I in an angular zone? ${NgZone.isInAngularZone()}`);
this.ngZone.run(() => {
that.log.debug(`connectionStateEvent triggered! state is: ${connectionState}`);
that.bluetoothDisconnected = !connectionState;
that.pageData.set("isBluetoothConnected", connectionState);
that.pageData.notify({ object: that.pageData, …Run Code Online (Sandbox Code Playgroud) 您好我是移动开发和Angular 2的新手.我正在尝试请求阅读联系人的权限,但是NativeScript无法识别"android".
例如,我无法运行以下代码:
permissions.requestPermission(android.Manifest.permission.INTERNET, "I need these permissions because I'm cool");
Error: Cannot find name 'android'.
任何帮助将不胜感激.
android android-permissions nativescript angular2-nativescript angular
javascript nativescript angular2-nativescript nativescript-angular angular
我想在登录表单中显示/隐藏密码文本。我有下面的代码。
我尝试以下代码:
<GridLayout margin="10" verticalAlignment="center" backgroundColor="#ffffff">
<StackLayout margin="10" verticalAlignment="center" [formGroup]="signUpForm" padding="15">
<StackLayout class="input-field">
<TextField formControlName="username" hint="Username"></TextField>
</StackLayout>
<StackLayout class="input-field">
<TextField formControlName="password" hint="Password" secure="true">
</TextField>
</StackLayout>
<Label text ="show/hide" (tap)="toggleShow()"></Label>
</StackLayout>
</GridLayout>
Run Code Online (Sandbox Code Playgroud)
在component.ts中,我编写了以下代码:
export class LoginComponent implements OnInit {
signUpForm: FormGroup;
show = false;
type= 'password';
constructor(....) {
this.signUpForm = this.formBuilder.group({
username: ["", Validators.required],
password: ["", Validators.required]
});
}
toggleShow()
{
this.show = !this.show;
if (this.show){
this.type = "text";
}
else {
this.type = "password";
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我点击功能toggleShow()中 …
show-hide typescript nativescript angular2-nativescript angular
我使用以下命令新安装了 Nativescript Angular 项目:
\nng new --collection=@nativescript/schematics my-mobile-app\nRun Code Online (Sandbox Code Playgroud)\n我从nativescript-schematics获得的命令
\n全新安装后,我尝试在 Android 模拟器上运行它。
\ntns run android\nRun Code Online (Sandbox Code Playgroud)\n然后我在编译过程中收到此错误:
\nSearching for devices...\nPreparing project...\nFile change detected. Starting incremental webpack compilation...\n\nwebpack is watching the files\xe2\x80\xa6\n\nHash: c018afa003f9a5a7d1cd\nVersion: webpack 4.44.2\nTime: 4451ms\nBuilt at: 11/05/2020 1:54:33 PM\n 3 assets\nEntrypoint bundle = runtime.js vendor.js bundle.js\n[./app.css] 1.05 KiB {bundle} [built]\n[./main.ts] 1.13 KiB {bundle} [built]\n[~/package.json] external "~/package.json" 42 bytes {bundle} [optional] [built]\n + 331 hidden modules\n\nERROR in error TS5060: Option \'paths\' cannot be used without …Run Code Online (Sandbox Code Playgroud) webpack nativescript angular2-nativescript nativescript-angular angular
nativescript ×9
angular ×7
android ×2
javascript ×2
typescript ×2
show-hide ×1
webpack ×1
zone ×1