错误NativeScript-显示空应用程序而不是内容

时间:2019-05-21 08:39:09

标签: android angular nativescript angular7 nativescript-angular

我使用Angular v7创建了一个Web应用程序,现在我想将Web应用程序迁移到NativeScript移动应用程序。我遵循了NativeScript官方网站上的指示,并且一切正常,直到为移动应用程序调整代码为止。

现在我在Android移动设备上运行我的应用程序时,出现错误

  

未将此视图添加到此实例视图stacklayout(2),CurrentParent   未定义,ExpectedParent:AppHostView(1)

有时我只是看到一个空的应用程序。我究竟做错了什么?抱歉,但是我不熟悉迁移和代码共享。

我的 app.component.tns.html

<!-- https://docs.nativescript.org/angular/core-concepts/angular-navigation.html#page-router-outlet -->
<StackLayout class="text-align:center">
    <Label>
      Welcome to {{ title }}!
    </Label>
</StackLayout>
<weather-search></weather-search>
<weather-list></weather-list>
<page-router-outlet></page-router-outlet>

我的 weather-list.component.tns.html

<StackLayout class="weather-list">
  <weather-item *ngFor="let weatherItem of weatherItems" [item]="weatherItem"></weather-item>
</StackLayout>

<!--
Original Web template:

<section class="weather-list">
    <weather-item *ngFor="let weatherItem of weatherItems" [item]="weatherItem"></weather-item>
</section>
-->

我的 weather-search.component.tns.html

<FlexboxLayout class="weather-search">
    <StackLayout class="test_up">
        <Label class="city" text="City"></Label>
        <TextField name="location" id="city" ngModel required></TextField>
    </StackLayout>
    <StackLayout class="test_down">
        <Label class="city" text="Country Code"></Label>
        <TextField name="countryCode" id="code" ngModel required></TextField>
        <Button text="Add City" (tap)="onSubmit(f)"></Button>
    </StackLayout>
</FlexboxLayout>
<Button text="Get geolocation" (tap)="onClickLocationData(f)"></Button>
<Label class="map" *ngIf="latitude!=0" text="{{latitude}}"></Label>
<Label class="map" *ngIf="longitude!=0" text="{{longitude}}"></Label>
<StackLayout id="map" class="mapLocation"></StackLayout>

<!--
Original Web template:

<section class="weather-search">
    <form (ngSubmit)="onSubmit(f)" #f="ngForm">
        <div class="test_up">
            <label for="city" class="city">City</label>
            <input name="location" type="text" id="city" ngModel required>
        </div>
        <div class="test_down">
            <label for="countryCode" class="city">Country Code</label>
            <input name="countryCode" type="text" id="code" ngModel required>
        </div>
        <button type="submit">Add City</button>
    </form>
    <button (click)="onClickLocationData(f)">Get geolocation</button>
    <label for="latitude" class="map" *ngIf="latitude!=0">Latitude: {{latitude}} </label>
    <label for="longitude" class="map" *ngIf="longitude!=0">Longitude: {{longitude}} </label>
    <div id="map" class="mapLocation"></div>
</section>
-->

我的 weather-item.component.tns.html

<StackLayout class="weather-element">
    <StackLayout class="col-1">
        <Label text="{{ weatherItem.cityName }}"></Label>
        <Label class="info" text="{{ weatherItem.description }}"></Label>
    </StackLayout>
    <StackLayout class="col-2">
        <Label class="temperature" text="{{ weatherItem.temperature }}"></Label>
    </StackLayout>
</StackLayout>

<!--
Original Web template:

<article class="weather-element">
    <div class="col-1"> 
        <h3>{{ weatherItem.cityName }}</h3>
        <p class="info">{{ weatherItem.description }}</p>
    </div>
    <div class="col-2"> 
        <span class="temperature">{{ weatherItem.temperature }}°C</span>
    </div>
</article>
-->

我的 app-routing.module.tns.ts

import { NgModule } from '@angular/core';
import { NativeScriptRouterModule } from 'nativescript-angular/router';
import { Routes } from '@angular/router';

const routes: Routes = [];

@NgModule({
  imports: [NativeScriptRouterModule.forRoot(routes)],
  exports: [NativeScriptRouterModule]
})
export class AppRoutingModule { }

1 个答案:

答案 0 :(得分:0)

您的app.component.html不能包含多个UI元素。您必须使用自己的UI选择布局来包装它。