My goal is to enhance the clarity of my Angular code by transitioning from using this.vm to angular.extend to better understand private and public variables/methods when utilizing the controller as syntax. However, I am facing an issue with data binding from a resolved promise.
// public data to view
var resolvedData;
var otherVar;
angular.extend(this, {
myVar: resolvedData,
mySecondVar: otherVar
})
myFactoty.action().then(function(data){
resolvedData = data;
})
When implementing the code in the above manner, I am unable to achieve data binding in my view. To address this, I attempted the following approach:
// public data to view
var resolvedData;
var otherVar;
angular.extend(this, {
myVar: resolvedData,
mySecondVar: otherVar
})
myFactoty.action().then(function(data){
angular.extend(this, {
myVar: data
})
})
However, this resulted in an error message: "Cannot read property '$$hashKey' of undefined."
How can I establish proper data binding in a manner that aligns with best practices?
Thank you.