【问题标题】:How do I call API on angular dom, given that API calls on plain nativescript is working?鉴于普通 nativescript 上的 API 调用正在工作,我如何在 angular dom 上调用 API?
【发布时间】:2017-12-22 17:06:14
【问题描述】:

库内失败,tns_modules 中的inside the prototype method,我猜this._android 未定义。

_createUI() 似乎从未被调用过。

错误:

TypeError:无法读取未定义的属性“addHeart” 文件:“file:///data/data/org.nativescript.bbnsng210June/files/app/tns_modules//bundles/core.umd.js,行:13024,列:8

堆栈跟踪: 框架:函数:'PeriscopeHearts.addHeart',文件:'file:///data/data/org.nativescript.bbnsng210June/files/app/tns_modules/nativescript-periscopehearts/periscopehearts.js',行:19,列:22 框架:函数:'WebRtcViewComponent.newHeart',文件:'file:///data/data/org.nativescript.bbnsng210June/files/app/modules/webrtcview/webrtcview.component.js',行:39,列:24 框架:函数:'',文件:'',行:81,列:24 框架:函数:'handleEvent',文件:'file:///data/data/org.nativescript.bbnsng210June/files/app/tns_modules//bundles/core.umd.js',行:11805,列:138

调用代码是这样的:

  @ViewChild('heartLayout') heartLayout_el: ElementRef;
  ngAfterViewInit(): void {
    this.peri_heart_el_native = <PeriscopeHearts>(this.heartLayout_el.nativeElement);
    alert('this.peri_heart_el_native:' + this.peri_heart_el_native); //PeriscopeHearts(771)
  }
  newHeart() {
    let colorArray = [{ hex: "#3489db" }, { hex: '#FF4081' }, { hex: '#229911' }, { hex: '#fff000' }];
    let rand = colorArray[Math.floor(Math.random() * colorArray.length)];
    this.peri_heart_el_native.addHeart(rand.hex);
  }

和模板:

<side-drawer-page>
  <StackLayout class="coverImage">
    <Button text="Add Heart" (tap)="newHeart()"></Button>
    <PeriscopeHearts #heartLayout class="heartLayout" height="400">
    </PeriscopeHearts>
  </StackLayout>
</side-drawer-page>

PS:plugin 上的 github 问题已经创建,但它更多的是角度问题,而不是特定于插件的问题,因此在此处复制。

【问题讨论】:

    标签: angular nativescript angular2-nativescript


    【解决方案1】:

    尝试使用loaded 事件来获取对heartLayout 的引用

    例如

    onLoaded(args) {
       this.peri_heart_el_native = <PeriscopeHearts>args.object;
    }
    

    在您的 HTML 中

    <PeriscopeHearts (loaded)="onLoaded($event)" class="heartLayout" height="400">
    

    【讨论】:

      猜你喜欢
      • 2021-09-02
      • 2018-11-23
      • 1970-01-01
      • 2022-07-25
      • 2015-12-03
      • 2019-02-05
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      相关资源
      最近更新 更多