0

我一直在让 nativescript 在正式版本中与 angular 2 一起工作时遇到很糟糕的事情。我对良好的 ole 派系网络角度零问题,但本机脚本是另一回事。NativeScript 为什么我的 hello world 可以工作?我什么也没看见。

谢谢

家:

import {Component} from "@angular/core";
import { Router } from "@angular/router";

@Component({
    selector: "home",
    template: "hello",
})
export class HomeComponent {
    constructor(private router: Router){
    }
}

应用程序

import {Component} from "@angular/core";

@Component({
    selector: "main",
    template: "<page-router-outlet></page-router-outlet>",
})
export class AppComponent {

}

路线:

import { HomeComponent } from "./pages/home/home.component";

export const routes = [
  { path: "", component: HomeComponent }
];

export const navigatableComponents = [

    HomeComponent
];

模块:

import { NgModule } from "@angular/core";
import { NativeScriptFormsModule } from "nativescript-angular/forms";
import { NativeScriptHttpModule } from "nativescript-angular/http";
import { NativeScriptModule } from "nativescript-angular/platform";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { AppComponent } from "./app.component";
import { HomeComponent } from "./pages/home/home.component";
import { routes, navigatableComponents } from "./app.routes";


@NgModule({
  imports: [
    NativeScriptModule,
    NativeScriptFormsModule,
    NativeScriptHttpModule,
    NativeScriptRouterModule,
    NativeScriptRouterModule.forRoot(routes)
  ],
  declarations: [AppComponent,
   ...navigatableComponents ],
  bootstrap: [AppComponent]
})
export class AppModule {}



Executing before-prepare hook from /Users/Documents/frontend/bootops-mobile-v1/hooks/before-prepare/nativescript-dev-typescript.js
Project successfully prepared (ios)
Transferring project files...
Successfully transferred all files.
Applying changes...
Sep 17 23:05:18 Davids-iMac com.apple.CoreSimulator.SimDevice.D28D29C3-07B6-4B60-B4B0-711475C505DE.launchd_sim[19187] (UIKitApplication:org.nativescript.bootopsmobilev1[0x7351][20309]): Service exited due to Terminated: 15
Successfully synced application org.nativescript.bootopsmobilev1 on device D28D29C3-07B6-4B60-B4B0-711475C505DE.
Sep 17 23:05:19 Davids-iMac bootopsmobilev1[20349]: objc[20349]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x124c81910) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x124aab210). One of the two will be used. Which one is undefined.
Sep 17 23:05:19 Davids-iMac bootopsmobilev1[20349]: assertion failed: 15G1004 14A345: libxpc.dylib + 62597 [37A9DF49-35C1-3D93-B854-B35CACF0100F]: 0x7d
Sep 17 23:05:19 Davids-iMac bootopsmobilev1[20349]: CONSOLE LOG file:///app/tns_modules/@angular/core/bundles/core.umd.js:210:20: Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.
4

2 回答 2

0

在 index.html 中,你必须把<selector-for-the-page></selector-for-the-page>你可能有不同的选择器。

于 2016-12-13T13:23:59.343 回答
0

除了带有 的部分之外,您的代码片段中的所有内容看起来都不错HomeComponent template,该组件声明应如下所示:

@Component({
    selector: "home",
    template: `<Label text="hello"></Label>`,
})
export class HomeComponent {
    constructor(private router: Router){
    }
}

这背后的原因是,在 NativeScript 中没有 webview,它都是原生组件。因此,为了呈现您的“hello”文本,您需要使用 NativeScript Label。这对于 NativeScript + Angular 2 来说都是正确的。您的代码片段在 Angular 2 Web 上可以正常工作,因为 Web 浏览器知道如何渲染该文本,另一方面 NativeScripts Angular 2 渲染器不知道如何直接渲染文本,因为在 iOS而Android没有这样的渲染,你需要通过Label标签告诉它如何。

于 2016-09-18T09:46:28.893 回答