Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom decorator doesn't work with aot compilation #13386

Closed
milne-dev opened this issue Dec 12, 2016 · 5 comments
Closed

Custom decorator doesn't work with aot compilation #13386

milne-dev opened this issue Dec 12, 2016 · 5 comments

Comments

@milne-dev
Copy link
Contributor

I'm submitting a ... (check one with "x")

[X] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
The decorator is called "authenticated" and calls the method it is decorating if the current user is authenticated, otherwise the login/signup modal is opened up instead.

Expected behavior
When I compile my app with the --aot flag (I'm using angular-cli), my custom decorator does not work as expected. This should continue to work the same with aot compilation.

Minimal reproduction of the problem with instructions
This is the code for the decorator:

export interface AuthenticatedServices {
	authService: AuthService;
}

export function authenticated(target: AuthenticatedServices, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) {
	let originalMethod = descriptor.value;

	descriptor.value = function(...args: any[]) {
		if (!this.authService.isAuthenticated$.value) {
			return this.authService.openLoginSignup();
		}

		return originalMethod.apply(this, args);
	};
}

This decorator can be used on any method of a class that implements the AuthenticatedServices interface like so:

@Component({selector: 'upvote', templateUrl: 'upvote.component.html'})
export class AwesomeUpvoteComponent implements AuthenticatedServices {
	constructor(public authService: AuthService) {}

        @authenticated
        toggleUpvote() {
	        this.superUpvotingServiceOnlyAuthenticatedUserCanCall.toggleUpvote();
        }
}

Please tell us about your environment:

  • Angular version: 2.2.1
  • Browser: Chromium 55
  • Language: TypeScript 2.0.3

  • Node (for AoT issues): node --version = 7.2.1

@ericmartinezr
Copy link
Contributor

Have you seen this issue angular/angular-cli#2799 ?

@milne-dev
Copy link
Contributor Author

Nope. I did a search for 'decorator' before posting, but nothing relevant came up.

@milne-dev
Copy link
Contributor Author

Didn't realize it was a cli issue. Thanks for the link.

@robwormald
Copy link
Contributor

closing as this is specific to angular-cli.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants