我可以轻松地设想自己将警报服务注入我的几乎所有控制器中:
myApp.factory('AlertsList', function () {
return [{ type: 'info', msg: 'Welcome!'},
{ type: 'success', msg: 'Checkout this subpage'}]
});
/* E.g.: for this controller */
function AlertsCtrl($scope, AlertsList) {
$scope.alerts = AlertsList;
$scope.closeAlert = function (index) {
$scope.alerts.splice(index, 1);
}
}
AlertsCtrl.$inject = ['$scope', 'AlertsList'];
停止扩展样板;如何使用此警报服务更新AngularJS的rootScope?