【发布时间】:2017-02-09 16:30:45
【问题描述】:
在本段下方的代码块中,您可以看到Twilio.Device.incoming,我将this.connection 设置为conn。
@Injectable()
export class BaMsgCenterService {
public getData;
public incomingCall = false;
public connection;
constructor(private http: Http) {
this.initTwilio();
Twilio.Device.ready(function (device) {
self.incomingCall = true;
$(".card-title").text("Ready to receive incoming calls!");
});
Twilio.Device.incoming(function (conn) {
console.log(conn.status);
this.incomingCall = true;
this.connection = conn;
});
//other functions
}
}
}
比我有一个组件类:
import {Component} from '@angular/core';
import { Http } from '@angular/http';
import {BaMsgCenterService} from './baMsgCenter.service';
@Component({
selector: 'ba-msg-center',
providers: [BaMsgCenterService],
styleUrls: ['./baMsgCenter.scss'],
templateUrl: './baMsgCenter.html'
})
export class BaMsgCenter {
public connection;
constructor(private _baMsgCenterService:BaMsgCenterService) {
this.connection = this._baMsgCenterService.connection;
}
pickup() {
this.connection.accept();
}
}
在 html 代码中我有一个(click)="pickup()"
但是,当我单击它时,它说 conn 不存在。
inline template:63:10 caused by: Cannot read property 'accept' of undefined
我想让拾取功能工作,它必须能够在拾取功能中使用 conn(或 this.connection)。我认为 Twilio.Device 稍后执行(它是一个 API)...
【问题讨论】:
标签: javascript jquery angular typescript twilio