0

How to send encode string as a parameter into URL string in angular and open in new tab. I am trying to send multiple parameter separated by '-' and converted into base64 encode through url but it is throwing me into not found. I am using angular 8. using router.navigate , it is working fine but I want to open url in new tab.

here is my code in TS.

 goToAssessmentPage(event, assignmentId, courseId, studentId, instituteId, sectionId , assignment_submission_id) {
    event.preventDefault()
    const string:string = btoa(courseId + '-' + assignmentId + '-' + studentId + '-' + instituteId + '-' + sectionId + '-' + assignment_submission_id)
    const url: string = string + '/grader-assessment';
    window.open(url, '_blank');
  }

app.routing.ts

{
    path: ':params/grader-assessment',
    component: GraderAssessmentPageComponent
},
2
  • 1
    did you try to put the url in <a> with router link and target _blank? Commented Nov 27, 2019 at 12:28
  • @BrunoCerecetto - That would be a nice solution too if it can be used in his case. Commented Nov 27, 2019 at 12:30

1 Answer 1

1

Well you'll more than likely need the whole url tree in that url string for window.open to work.

From the docs (https://angular.io/api/router/Router#createurltree)

// create /team/33/user/11
router.createUrlTree(['/team', 33, 'user', 11]);

And on top of that (https://angular.io/api/router/Router#serializeurl)

serializeUrl(url: UrlTree): string

So in your case it would be something like:

const string:string = btoa(courseId + '-' + assignmentId + '-' + studentId + '-' + instituteId + '-' + sectionId + '-' + assignment_submission_id)
const fullUrl:string = this.router.serializeUrl(router.createUrlTree([string, '/grader-assessment']));
// Then you navigate to this full url
window.open(fullUrl, '_blank');
Sign up to request clarification or add additional context in comments.

1 Comment

this is perfect way of openingURL in new tab in angular with parameters sent in encoded manner.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.