On my webpage, I need to load a matrix of data in the form of a table. To achieve this, I make three requests to obtain all the necessary data:
- Data for columns
- Data for rows
- Data for relationships
Once I have gathered all the data, I utilize a function called
getRelation(columnIndex, rowIndex)
to retrieve the relationship data.
However, if the rows are loaded before the columns, Angular will attempt to execute the getRelation
method for rendering. This can lead to an error because the column data is not yet available.
I could potentially include an if
condition within my function to handle this scenario, but I am curious if there is a better way to address this issue?
this.relations = [];
this.columns = [];
this.rows = [];
this.getRalation = function getRalation(columnIndex, rowIndex) {
var column= this.columns[columnIndex];
var row= this.rows[rowIndex]
var relation = $myService.getSomthing(this.relations, column.ID, row.ID);
return relation;
}.bind(this);
$http.post(url, {}).then(function(res) {
this.rows = res.data;
}.bind(this));
// similar code implementation for columns and relations