簡體   English   中英

組件HTML中的Angular 2調用函數返回空

[英]Angular 2 Calling function from Component HTML returns empty

這是我的ts文件。 每當我在另一個或相同的打字稿中調用tempData()方法時,它將返回正確的信息。 但是,當我把它從HTML文件它this.links.length返回0,並返回this.graph錯誤ID

export class EditRelationColsComponent implements OnInit {
  graph: any = new joint.dia.Graph;


constructor(private globalService: GlobalService) {
  }

ngOnInit() {
 }
  tempData(){
    console.log(this.graph);
    console.log(this.links.length);
 }
}

HTML

<button class="diag" pButton type="button" (click)="tempData()"  class="ui-button-info" label="Save"></button>

因此,當我從另一個JS調用函數時(在我調用loadGraph()之后 ),我的圖形ID為:307當我從HTMl調用函數時,我的圖形ID為:308。我不知道為什么它不在尋找合適的圖形,而是創建一個新的?

關閉標記“}”的速度過快。 嘗試這個。

export class EditRelationColsComponent implements OnInit {
  graph: any = new joint.dia.Graph;


  constructor(private globalService: GlobalService) {
  }

 ngOnInit() {
 }
 tempData(){
    console.log(this.graph);
    console.log(this.links.length);
 }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM