I have a $scope.currentUser object and a nested OwnedCompany object like so:
app.controller 'dashboardsCtrl', ($scope, Api, Auth) ->
$scope.currentUser = Api.User.get(id: Auth.user())
$scope.ownedCompany = $scope.currentUser.owned_company
{{currentUser}} returns:
user: {
"name": "Ryan",
"owned_company":{"name":"XYZ"}
}
{{currentUser.owned_company}} returns:
{"name":"XYZ"}
but {{ownedCompany}} returns nil.
How do I get $scope.ownedCompany = $scope.currentUser.owned_company to work?
Solution
As per @mohamedrias' answer,
app.controller 'dashboardsCtrl', ($scope, Api, Auth) ->
Api.User.get(id: Auth.user()).$promise.then (currentUser) ->
$scope.currentUser = currentUser
$scope.ownedCompany = currentUser.owned_company
{{ownedCompany}} returns:
{name:"XYZ"}
currentUser.owned_companyis changed at run time then use a watch or set the value after the change is happened - jsfiddle.net/arunpjohny/jpno6ft2/2$scope.currentUser.owned_companyreturns an object with property name so try{{ownedCompany.name}}to getXYZ