I have the following code, and I am trying to set the value of a $scope variable after a promise (in this case an $http request) is finished. The code looks like this:
.controller('NewItemCtrl', function ($scope, $state, LabelFactory) {
$scope.createItem = function (item) {
LabelFactory.createLabel(item)
.then(function (response) {
$scope.label = response.data;
$scope.thing = 'These are things';
$state.go('tab.newitem-label');
console.log($scope.label);
});
};
})
And it looks like it should work but it doesn't. Even though I am able to log $scope.label correctly, when I look for that item in my template (for which NewItemCtrl is the controller), nothing is there. It is as if I never sent it at all, even though it obviously has a value.
Can someone explain to me how to either A. Set the value of$scope property from inside another scope,or B. the best practice to achieve the same thing?
console.logpart is not what is important - setting the$scopevalue for use elsewhere in the app is.