我有一个包含对象的数组。当我将新对象推送到此列表时,视图不会更新以添加新对象。我认为它与 $scope.$apply 有关,但我不确定如何使用它。我已经尝试将推送功能包装在这个周围,但工厂说 $scope 是未定义的。
看法:
<label for="groupOwner">List Template:
<select
id="listTemplate"
ng-model="newList.template"
ng-options="t.name for t in listTemplates|orderBy: 'name'"
></select>
</label>
控制:
$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);
});
};
服务功能:
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")
}
});
}