这是我使用的代码。在php调用成功后,我触发了click事件。但它不在hte http get里面工作。如果我把它放在http方法之外它就可以工作了。
在component.html中
<a #myDiv id="anchorID" href="{{details.url}}&a={{affid}}&b={{sid}}&c={{ordid}}" target="_blank"></a>
在component.ts中
this.http.get(this.apiurl+'api/insertorder.phpumid="+this.loginid).subscribe(data=>{
var jsonData = data.json();
let urlpass = jsonData.url;
this.ordid = jsonData.orderid;
$("#anchorID")[0].click();
},error => {
console.log('error in sub');
console.log(error);
});
这有什么问题。在成功之后我需要打电话给我。
如果我使用window.open(urlpass,'_blank');
然后它会创建弹出窗口阻止程序问题。请帮忙解决这个问题。
不仅使用JQuery和Angular是不好的做法,但你甚至在模板中使用局部变量让Angular做到这一点。
试试这个。
@ViewChild('myDiv') div: ElementRef;
并用。替换你的JQuery代码
this.div.nativeElement.click();
对于您的问题,这可能意味着您的HTTP调用没有成功。做到了 ?