【问题标题】:how to display hello world text in ionic 2 using typescript?如何使用打字稿在 ionic 2 中显示 hello world 文本?
【发布时间】:2016-04-23 11:25:33
【问题描述】:

我正在尝试使用类型脚本学习 ionic 2。您能告诉我如何 使用 typescript 在 ionic 2 中显示 hello world 文本? 我能够以角度 2 显示 hello world 文本。我想使用 ionic 2 并显示文本。

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

能否请您告诉 ionic 2 需要包含哪些库才能显示文本。 这是离子 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)

请分享一下

【问题讨论】:

    标签: angular ionic2


    【解决方案1】:

    在 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。

    【讨论】:

    • 我们可以做 plunker 吗?
    • 抱歉,在这种情况下无法为您提供 plunkr,因为 ionic2 项目具有特定的结构和构建。您可以使用ionic start 命令非常轻松地生成项目。要启动它,只需在...之后执行ionic serve...
    猜你喜欢
    • 1970-01-01
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 2017-09-12
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 2017-12-05
    相关资源
    最近更新 更多