この段落の下のコードブロックでは、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
}
}
}
:HTMLコードで
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();
}
}
を私はしかし(click)="pickup()"
を持って、私はそれをクリックしたとき、それはconnが存在しないことを言います。
inline template:63:10 caused by: Cannot read property 'accept' of undefined
私はそのピックアップ機能の仕事をしたいと思い、そのピックアップ機能でCONN(またはthis.connection)を使用することができなければなりません。 Twilio.Deviceが後で実行されると思います(APIです)。
ええ、彼は間違った言語の構文か間違った言語のセマンティクスのいずれかを使用しています。 –
あなたの答えで最初の問題が解決されたら、私は問題に答えたと思います。 :) – philnash
フェア - ; –