angular-decorator

Angular - Custom method decorator which triggers console.log() at the beginning and end of a method

一个人想着一个人 提交于 2020-08-21 17:34:18
问题 I would like to know if it is possible to create a custom decorator in Angular which when applied to a method can achieve the following functionality: console log at the beginning of a method console log at the end of a method Example: Without Decorator: getRelationshipSource() { console.log('Entering getRelationshipSource method'); this.referenceDataService.getRefData('RLNSHPSC').subscribe(res => { this.relationshipSource$.next(res); }); console.log('Leaving getRelationshipSource method'); }

Why does Angular 2 use decorators?

元气小坏坏 提交于 2020-03-13 06:02:35
问题 I just started using Angular 2 and was wondering why some properties like selector and template are put in components decorators and not in components classes. What's the point of using all these decorators in Angular 2? 回答1: To make it easy for tools to provide all kinds of support in templates like: error checking auto-completion graphical GUI designers To generate code from decorators which allows: to define some things more declaratively or generate different code depending on some

Why does Angular 2 use decorators?

别说谁变了你拦得住时间么 提交于 2020-03-13 06:01:13
问题 I just started using Angular 2 and was wondering why some properties like selector and template are put in components decorators and not in components classes. What's the point of using all these decorators in Angular 2? 回答1: To make it easy for tools to provide all kinds of support in templates like: error checking auto-completion graphical GUI designers To generate code from decorators which allows: to define some things more declaratively or generate different code depending on some

How to decorate current state resolve function in UI-Router? Current function isn't invoked

亡梦爱人 提交于 2020-01-09 10:32:34
问题 I'm trying to DRY in $stateProvider and prevent adding the same auth function in each resolve. I've created decorator that in each state change would add this function to current state, but auth function isn't invoked, How to fix it or how to workaround discussed issue? app.config(function ($stateProvider, $urlRouterProvider, $provide) { $provide.decorator('$state', function($delegate, $rootScope) { $rootScope.$on('$stateChangeStart', function(event, state, params) { if ($delegate.current ===

Adding Angular directive using decorator

梦想的初衷 提交于 2019-12-24 13:48:49
问题 I'm using Angular 1.4.8 with Angular UI. What I'm trying to do is decorate the ui-sref directive so it will highlight a menu element (by setting the CSS class 'active') if the current $state.name matches the ui-sref state. I test to see if the element is descendent from my nav header, and if it is, I want to add an ngClass attribute to the element. For right now, I just want to make them all highlight; I can add the test for matching the state later. The true will be replaced with the actual

What is a better way and how to achieve sending object from one nested component to another

送分小仙女□ 提交于 2019-12-11 05:59:57
问题 I'm working on simple application about products, basically when user choose a product it should be sent to another component which would hold product. Product is allways choosen one by one, I am NEVER sending a LIST ! Only item by item ! So basically when I click on any of products in the middle of screen ( Product food 1, Product food 2, Product food 3 ) it should be sent to the right part of the screen which is also separated component. So my middle component looks like this: <div *ngFor=

AngularJS Decorator without object.defineProperty

安稳与你 提交于 2019-12-08 10:23:19
问题 How do I use decorators without having access to object.defineProperty? I am looking into the shims available: es5-sham polyfill but in case those don't pass testing, is there another way decorators were intended to work? I am using the decorator for $onRootScope. I am using angular 1.08. I need compatibility with IE7. Update I have tried out a few methods that seem to work but I don't know the difference between them: plunkr var app = angular.module('plunker', []); app.config(['$provide',

Angular's `@Host` decorator not reaching the top?

老子叫甜甜 提交于 2019-12-05 01:16:04
问题 In my main app.ts I've declared a global provider : providers: [{provide: Dependency, useValue: createDependency('AppModule provider')}] ( Where createDependency is just a function that returns a class which has a getName() method. ) I also have a components : <my-app-component-3>Hello from 3</my-app-component-3> Code : @Component({ selector: 'my-app-component-3', template: ` <div>Component3: <ng-content></ng-content> : <span [innerHTML]="dependency?.getName()"></span> </div> `, }) export

Angular's `@Host` decorator not reaching the top?

£可爱£侵袭症+ 提交于 2019-12-03 16:15:28
In my main app.ts I've declared a global provider : providers: [{provide: Dependency, useValue: createDependency('AppModule provider')}] ( Where createDependency is just a function that returns a class which has a getName() method. ) I also have a components : <my-app-component-3>Hello from 3</my-app-component-3> Code : @Component({ selector: 'my-app-component-3', template: ` <div>Component3: <ng-content></ng-content> : <span [innerHTML]="dependency?.getName()"></span> </div> `, }) export class Component3 { constructor(@Host() @Optional() public dependency: Dependency) {} } The result is:

Difference between @Self and @Host Angular 2+ Dependency Injection Decorators

我是研究僧i 提交于 2019-12-03 12:53:17
问题 Kindly explain the difference between @Self and @Host. The angular API documentation gives some idea. But it's not clear to me. The example provided for Self uses ReflectiveInjector to exemplify usage. However, one would rarely, if ever, use ReflectiveInjector in actual app code (probably more in testing).. Can you give an example of where you would use @Self instead of @Host outside of such test scenarios?? 回答1: tl;dr It looks like when @Self is used, Angular will only look for a value that