如何使用打字稿在 Ionic 2 中显示 Hello World 文本



我正在尝试使用类型脚本学习离子2.你能告诉我如何使用打字稿在 Ionic 2 中显示 Hello World 文本?我能够在角度 2 中显示你好世界文本.我想使用离子 2 并显示文本。

这是我使用角度 2 的代码http://plnkr.co/edit/xd0TbWO5deHB7xTjXibR?p=preview

您能否告诉 Ionic 2 库需要包含哪些内容才能显示文本。这是 Ionic 2 文档http://ionicframework.com/docs/v2/getting-started/tutorial/代码转到此处

import {bootstrap} from 'angular2/platform/browser';
import {Component} from 'angular2/core';

@Component({
  selector:'app',
  template:'<div>hello</div>'
})
class App{}

bootstrap(App)

请分享普伦克

在 Ionic2 中,您不使用@Component装饰器,而是使用@App@Page装饰器。使用@App,您无需引导应用程序。相应的类会自动定义为应用程序的主元素/入口点。

如果要显示 hello world 文本,只需使用 ionic start 命令生成即可。例如:

$ ionic start MyIonic2Project --v2

然后,您可以在app文件夹(在app.js文件中)下访问应用程序类。要显示一个简单的hello world,您可以尝试以下操作:

import 'es6-shim';
import {App, Platform} from 'ionic-angular';
import {StatusBar} from 'ionic-native';
@App({
  template: `
    <div>Hello world</div>
  `,
  config: {},
  providers: [ ]
})
export class MyApp {
  static get parameters() {
    return [[Platform]];
  }
  constructor() {
    platform.ready().then(() => {
      StatusBar.styleDefault();
    });
  }
}

请注意,ES6 在生成的项目中使用。

最新更新