【问题标题】:Ionic native component vs Angular custom component离子原生组件与 Angular 自定义组件
【发布时间】:2017-10-15 12:24:02
【问题描述】:

我使用this article创建了角度进度条组件。它工作正常。你能告诉我角度自定义组件和原生ionic component likeion-range有什么区别吗?

自定义角度组件:

import { Component, Input } from '@angular/core';

@Component({
  selector: 'progress-bar',
  templateUrl: 'progress-bar.html'
})
export class ProgressBarComponent {

  @Input('progress') progress;

  constructor() {

  }

}

【问题讨论】:

    标签: angular ionic-framework ionic2 components ionic3


    【解决方案1】:

    其实没什么区别。 Ionic 建立在 angular 之上。所有特定的离子组件都是使用角度组件装饰器构建的。 ion-range 之类的组件实际上是 ionic-angular 模块中的 Angular 组件。

    如果您检查链接的源代码,则显示为:

    @Component({
      selector: 'ion-range',
      template: '<!-- custom html here -->'
    
      providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: Range, multi: true } ],
      encapsulation: ViewEncapsulation.None,
    })
    export class Range extends BaseInput<any> implements AfterContentInit, ControlValueAccessor, OnDestroy {
    //..
    }
    

    每个 ionic 组件的输入属性使用 Angular 的 @input() 定义,所有输出事件(如 ionChange)使用 Angular 的 EventEmitter 定义。

    【讨论】:

    • 好的。这是否意味着,Angular 自定义组件将支持所有平台(android, ios and wp),如 Ionic 原生组件?
    • 这更多地与定义的 scss 以及在构建过程中获取的 scss 中的哪个有关..
    • 有特定的样式,如 .md、.ios 和 .wp.. 你只需要花一些时间来研究源代码 :) 。 github.com/driftyco/ionic/tree/master/src/components/range
    • 查看scss文件
    • 是的,知道了。您认为我们在开发 Angular 组件时是否还需要为每个平台添加此类 scss 文件,或者它在所有平台上都可以正常工作而没有任何重大问题?跨度>
    猜你喜欢
    • 1970-01-01
    • 2019-06-13
    • 1970-01-01
    • 1970-01-01
    • 2017-12-29
    • 1970-01-01
    • 2018-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多