angularjs-decorator

How to test angular decorator functionality

Deadly 提交于 2020-01-02 03:28:07
问题 I have a decorator in Angular that is going to extend the functionality of the $log service and I would like to test it, but I don't see a way to do this. Here is a stub of my decorator: angular.module('myApp') .config(function ($provide) { $provide.decorator('$log', ['$delegate', function($delegate) { var _debug = $delegate.debug; $delegate.debug = function() { var args = [].slice.call(arguments); // Do some custom stuff window.console.info('inside delegated method!'); _debug.apply(null,

Extending Scope function to Directive in Angular 1.4

。_饼干妹妹 提交于 2019-12-05 04:22:38
问题 I am trying to extend the angular-ui.github.io/bootstrap/ datepicker and it seems not to work. angular.module('myApp', [ 'ui.bootstrap' ]) .config(function($provide) { $provide.decorator('datepickerDirective', function ($delegate) { var directive = $delegate[0], link = directive.link; //works on 1.2 /* angular.extend(directive.scope, {'monthChanged': '&'}); */ // Not working in Angular 1.4 too. /*directive.$$isolateBindings['monthChanged'] = { attrName: 'monthChanged', mode: '&', optional:

Extending Scope function to Directive in Angular 1.4

对着背影说爱祢 提交于 2019-12-03 21:04:38
I am trying to extend the angular-ui.github.io/bootstrap/ datepicker and it seems not to work. angular.module('myApp', [ 'ui.bootstrap' ]) .config(function($provide) { $provide.decorator('datepickerDirective', function ($delegate) { var directive = $delegate[0], link = directive.link; //works on 1.2 /* angular.extend(directive.scope, {'monthChanged': '&'}); */ // Not working in Angular 1.4 too. /*directive.$$isolateBindings['monthChanged'] = { attrName: 'monthChanged', mode: '&', optional: true };*/ // Not working in Angular 1.4 too. directive.bindToController = { 'monthChanged': '&' };

How can I use decorators today?

天大地大妈咪最大 提交于 2019-12-03 15:14:27
问题 I see decorators being used today already in some javascript code. My question is really two fold. First: If decorators have not even been finalized how is it possible to use them in production code, today? Won't browser support be non-existent? Second: Given it is possible to use it today, as some open source projects would suggest, what's a typically recommended setup for getting decorators to work? 回答1: You're right, ES2016 decorators are not yet part of the spec. But it doesn't mean we

How can I use decorators today?

≯℡__Kan透↙ 提交于 2019-12-03 04:51:35
I see decorators being used today already in some javascript code. My question is really two fold. First: If decorators have not even been finalized how is it possible to use them in production code, today? Won't browser support be non-existent? Second: Given it is possible to use it today, as some open source projects would suggest, what's a typically recommended setup for getting decorators to work? You're right, ES2016 decorators are not yet part of the spec. But it doesn't mean we can't use it today. First let's take a step back and go over "what is a decorator". Decorators are simply

Ng-animate stopped working using $templateRequest decorator

谁说我不能喝 提交于 2019-12-01 06:23:37
I was trying to avoid template errors with angular js when my user became unauthenticated. To do this, I came to this stackoverflow solution . It worked for me, but now I noticed that my ng-animate stopped working without throwing console errors. What am I missing? Update: This is the code used var app = angular.module('app',[]); app.config(['$provide', function($provide) { $provide.decorator('$templateRequest', ['$delegate', function($delegate) { var mySilentProvider = function(tpl, ignoreRequestError) { return $delegate(tpl, true); } return mySilentProvider; }]); }]); The function

Ng-animate stopped working using $templateRequest decorator

廉价感情. 提交于 2019-12-01 03:04:11
问题 I was trying to avoid template errors with angular js when my user became unauthenticated. To do this, I came to this stackoverflow solution. It worked for me, but now I noticed that my ng-animate stopped working without throwing console errors. What am I missing? Update: This is the code used var app = angular.module('app',[]); app.config(['$provide', function($provide) { $provide.decorator('$templateRequest', ['$delegate', function($delegate) { var mySilentProvider = function(tpl,

Angularjs - Decorate Controllers

半城伤御伤魂 提交于 2019-11-30 14:51:49
I am trying to set up a decorator for my controllers. My intention is to introduce some common behaviour across all the controllers in my app. I have it configured to work in Angular 1.2.x, but there are some breaking changes from 1.3.x onwards that is breaking the code. The error one now gets is "controller is not a function" . Below is the code for the decorator: angular.module('myApp', ['ng'], function($provide) { $provide.decorator('$controller', function($delegate) { return function(constructor, locals) { //Custom behaviour code return $delegate(constructor, locals); } }) }); Angular 1.2

Angularjs - Decorate Controllers

梦想与她 提交于 2019-11-29 21:35:28
问题 I am trying to set up a decorator for my controllers. My intention is to introduce some common behaviour across all the controllers in my app. I have it configured to work in Angular 1.2.x, but there are some breaking changes from 1.3.x onwards that is breaking the code. The error one now gets is "controller is not a function" . Below is the code for the decorator: angular.module('myApp', ['ng'], function($provide) { $provide.decorator('$controller', function($delegate) { return function

What are “decorators” and how are they used?

和自甴很熟 提交于 2019-11-26 23:27:56
I'm curious what exactly decorators are in AngularJS. There isn't much information online for decorators save for a blurb in the AngularJS documentation and a brief (albeit interesting) mention in a youtube video . As the Angular guys put it a decorator is: Decoration of service, allows the decorator to intercept the service instance creation. The returned instance may be the original instance, or a new instance which delegates to the original instance. I don't really know what that means , and I'm not sure why you would separate this logic from the service itself. For example if I wanted to