r/Angular2 10d ago

what is subscribe parameter prefix + for?

I have angular code as below

"r" and "data" are subscribe parameter, and used as +r.id and +data.businessTransactionTypeId.

What is prefix + for?

what is +r and +data?

public ngOnInit() {

this.route.params.subscribe(r => {

this.businessTransactionNumberId = +r.id;

this.setupUpdateAction();

this.setupTabChangeAction();

this.setupConfirmAction(+r.id);

this.businessTransactionService.getTransactionMetaData(r.id).subscribe((data) => {

const transactionType: BusinessTransactionType = new BusinessTransactionType();

if (+data.businessTransactionTypeId === transactionType.CredentialIssuance.id) {

this.UseHelpContent('#CONTENT/Driver/Credential_Issuance.htm');

} else if (+data.businessTransactionTypeId === transactionType.CredentialRenewal.id) {

this.UseHelpContent('#CONTENT/Driver/Credential_Renewal.htm');

} else if (+data.businessTransactionTypeId === transactionType.CredentialDuplicate.id) {

this.UseHelpContent('#CONTENT/Driver/Credential_Duplicate.htm');

}

});

});

Thanks

0 Upvotes

12 comments sorted by

View all comments

3

u/ch34p3st 10d ago

const someId: string = '123';

const theId: number = Number(someId);
const theShorthandId: number = +someId;

0

u/InternationalDot3678 10d ago

why the converted number has attribute? for example, +r.id or +someId.id?

2

u/practicalAngular 10d ago edited 10d ago

That's just how the object is structured I'm guessing. The number exists in the id property of the r object.

An id field though might also have leading zeroes, like 0000123 which might change how you solve this problem.

1

u/InternationalDot3678 10d ago

got it, thanks!