一、nativescript第一个执行的文件:app/main.ts
import { platformNativeScriptDynamic } from "nativescript-angular/platform";
import { AppModule } from "./app.module";
platformNativeScriptDynamic().bootstrapModule(AppModule);
1.import是ts的导入命令
2.platformNativeScriptDynamic()创建angular本地应用程序app
3.bootstrapModule启动运行应用程序
bootstrapModule通过一个包含应用程序主配置的angular模块,即在app.moudle.ts中定义的 AppModule模块启动和运行应用程序
二、app.moudle.ts
import { NgModule } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { AppComponent } from "./app.component";
@NgModule({
imports: [NativeScriptModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
1.NgModule是我们组织Angular应用所必须的,后面需要实现双向数据绑定,还需要引入NativeScriptFormsModule模块
2.bootstarp:[AppComponent]
NgModule的引导程序属性设置为AppComponent,这个配置将控制权传递给app.component.ts文件中的AppComponent类
三、app.component.ts
import {Component} from "@angular/core";
@Component({
selector: "my-app",
template: "<Label text='hello world'></Label>"
})
export class AppComponent {}
1.Component是angular组件,是angular应用程序的主要构建块,组件给以构建view(一个UI元素或一个完整的页面)
2.组件类的语法@Component({})
@Component decorator(装饰器)的模板属性告诉NativeScript如何在屏幕上呈现该组件
3.selector:定义了组件如何在另一个组件的模板中使用