我有一个在我的模块中注册的控制器。但是,我想做的是访问 Angular 之外的 $scope,以便我可以更改模型。例如,我想做以下事情:
var sentboxCtrl = function ($scope){
$scope.sent = Sent;
$scope.deleteIcon = deleteIconSource;
$scope.flagIcon = flagIconSource;
$scope.attachmentIcon = attachmentIconSource;
for(var i = 0; i < $scope.sent.length ; i ++)
{
$scope.sent[i]['checked'] = false;
}
$scope.delete = function(element)
{
for(var i = 0; i < $scope.sent.length; i ++)
{
if($scope.sent[i].id == element.id)
{
$scope.sent.splice(i,1);
}
}
}
$scope.deleteChecked = function()
{
for(var i = 0; i < $scope.sent.length; i++)
{
if($scope.sent[i].checked)
{
$scope.sent.splice(i,1);
// We must account for sent.length changing
// after splicing so we need to decrement to
// account for that.
i --;
}
}
}
$scope.getModel = function()
{
return $scope;
}
};
我使用 sendboxCtrl.getModel 返回范围,然后我可以在正常上下文之外操作范围的属性。
我怎样才能做到这一点?