Hi there,
I’ve built an angularjs app and I cannot figure out why the $scope value is not displaying for one of the controllers in the app. The $scope is set to initialize a function… the function works as expected when set as the scope, but the return value never displays. I’ve tested by just using a string in place of the scope, and that prints fine. So my assumption is that it has something to do with the function for some reason. Any advice would be greatly appreciated.
Here’s a look at the code for the js.
//js
app.controller('tasksController', function($scope, $http){
function getPropertyID(){
return $http({
method: 'GET',
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/allProperties?$select=MSPWAPROJUID",
headers: {"Accept": "application/json; odata=verbose"}
})
}
function getTasks(projectID){
return $http({
method: 'GET',
url: _spPageContextInfo.webAbsoluteUrl + "/_api/ProjectData/Projects(guid'" + projectID + "')/Tasks",
headers: {"Accept": "application/json; odata=verbose"}
})
}
function getProjectInfo(){
return new Promise(function(resolve, reject){
getPropertyID().then
(function (projIDresponse){
console.log(projIDresponse.data.d.MSPWAPROJUID);
var ProjectUID = projIDresponse.data.d.MSPWAPROJUID;
console.log("heres the", ProjectUID);
getTasks(ProjectUID).success(function(tasksResponse){
console.log(tasksResponse);
var tasks = tasksResponse.d.results.length;
console.log("Got the", tasks);
resolve({
projectTasks: tasks
});
}).error(function(error){
console.log("There's some heauxes in the code", error);
reject(error);
});
});
});
};
$scope.tasks = getProjectInfo().then(function(results){
console.log("are these the results", results);
return results});
});