使用警报服务扩展rootScope?

时间:2013-07-15 10:07:43

标签: inheritance angularjs dry angularjs-scope angularjs-service

我可以轻松地设想自己将警报服务注入我的几乎所有控制器中:

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?

0 个答案:

没有答案