I am facing an issue with updating the view when a new object is pushed to an array that contains objects. It seems like the problem lies with $scope.$apply, but I'm not sure how to implement it properly. I attempted wrapping the push function in $scope.$apply, but the error message shows that $scope is undefined.
View:
<label for="groupOwner">List Template:
<select
id="listTemplate"
ng-model="newList.template"
ng-options="t.name for t in listTemplates|orderBy: 'name'"
></select>
</label>
Ctrl:
$scope.createList = function (){
var modalForm = '/Style%20Library/projects/spDash/app/partials/newList.html';
var modalInstance = $modal.open({
templateUrl: modalForm,
backdrop: true,
windowClass: 'modal',
controller: 'newListCtrl',
resolve: {
newListData: function (){
return $scope.newList;
}
}
});
modalInstance.result.then(function(newList){
SiteService.createList(newList,$scope.site);
});
};
Service function:
var createList = function (newList, site){
var promise = $().SPServices({
operation: "AddList",
webURL: site.url,
listName: newList.name,
description: newList.description,
templateID: newList.template.id
})
promise.then(function (){
addToQuickLaunch(newList.name,site.url)
getSiteInfo(site);
//take new list object and push to siteLists array
siteLists.push(newList);
},function (reason){
console.log('Failed: ' + reason);
})
}
function addToQuickLaunch (name,siteUrl) {
$().SPServices({
operation: "UpdateList",
webURL: siteUrl,
listName: name,
listProperties: "<List OnQuickLaunch='TRUE' EnableVersioning='TRUE'/>",
completefunc: function(xData,Status){
console.log(name + " list created")
}
});
}