Posts

Showing posts from June, 2015

Passing current scope to an AngularJS Service

var app = angular.module('as2App'); app.factory('AlertService', function($timeout) { var _scope = {}; //constructor function alertService(scope) { this._scope = scope; this._scope['show_alert'] = false; this._scope['alerts'] = []; } alertService.prototype._addAlert = function(type, message) { this._scope['alerts'].push({ type: type, msg: message }); this._onShow(this._scope); } alertService.prototype._onShow = function(_scope) { this._scope['show_alert'] = true; $timeout(function() { alertService.prototype._hideMe(_scope); }, 2000); } alertService.prototype._hideMe = function(_scope) { _scope['show_alert'] = false; _scope['alerts'].splice(0, 1); } return alertService; }); //########### SERVICES ############## //########### CNTROLLER ############## var app = angular.module('as2App'); app.controller