首页 文章

我如何在角度dom上调用API,因为普通nativescript上的API调用正在工作?

提问于
浏览
0

在库中失败,在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,line:13024,column: 8 StackTrace:框架:功能:'PeriscopeHearts.addHeart',文件:'file:///data/data/org.nativescript.bbnsng210June/files/app/tns_modules/nativescript-periscopehearts/periscopehearts.js',第19行, column:22 Frame:function:'WebRtcViewComponent.newHeart',file:'file:///data/data/org.nativescript.bbnsng210June/files/app/modules/webrtcview/webrtcview.component.js',line:39, column:24 Frame:function:'',file:'',line:81,column:24 Frame:function:'handleEvent',file:'file:///data/data/org.nativescript.bbnsng210June/files/ app / tns_modules // bundles / core.umd.js',line:11805,column: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问题,但它更像是一个角度问题,而不是特定于插件,因此在这里复制 .

1 回答

  • 0

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

    例如

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

    在你的HTML中

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

相关问题