An error has occurred in Angular: No routes were found that match the URL segment 'null'

I've recently developed a simple Angular page that extracts an ID (a guid) from the URL and uses it to make an API call. While I have successfully implemented similar pages in the past without any issues, this particular one is presenting challenges with embedding a YouTube video.

Oddly enough, when I print the YouTube URL to the console, it appears perfectly fine. However, after sanitizing it and assigning it to the src property of the iframe embed, the video fails to display. Strangely, if I alter the API description output from {{session?.SessionDescription}} to {{session.SessionDescription}}, the video shows up.

The description text loads regardless of which approach I take. Yet, omitting the question mark results in a console error indicating that the description cannot be loaded, despite being visible on the screen.

I simply aim for both elements to load smoothly without triggering any console errors.

HTML:

<nav class="pure-drawer" data-position="left">
    <h1>What is 3D Printing?</h1>
    <p>{{session?.SessionDescription}} {{session?.SessionGains}}</p>
</nav>   

<div class="pure-pusher-container">
    <div class="pure-pusher">
        <!-- Copy & Pasted from YouTube -->
        <iframe width="560" height="349" [src]="vidUrl" frameborder="0" allowfullscreen></iframe>
    </div>
</div>

Typescript:

getCurrentSession(){
    this.sub = this.route.params.subscribe(params => {
      this.id = params['id']; 
      this._wmapi
      .getService("Session/" + this.id)
      .then((result) => {
        this.session = result;
        this.vidUrl = this.sanitizer.bypassSecurityTrustResourceUrl(result.SessionVideo);
        this.getSessionResources(this.id);
      })
      .catch(error => console.log(error));
    });
  }

Answer №1

It seems that the issue arises when there is no question mark used in the code snippet.

<p>{{session.SessionDescription}} {{session?.SessionGains}}</p>

This occurs because the session variable is initially undefined and does not progress to the iframe. On fetching the session, the component refreshes and the iframe receives a valid resource URL.

Conversely, by employing the question mark as shown below:

<p>{{session?.SessionDescription}} {{session?.SessionGains}}</p>

The line of code does not throw an error. Instead, it loads the iframe with an 'undefined' URL since the response from the API is pending. Subsequently, it fails to detect the change and refresh the iframe.

To potentially resolve this issue, consider modifying your code as follows:

<nav class="pure-drawer" data-position="left">
    <h1>What is 3D Printing?</h1>
    <p>{{session?.SessionDescription}} {{session?.SessionGains}}</p>
</nav>   

<div class="pure-pusher-container">
    <div class="pure-pusher" *ngIf="vidUrl"> <!-- NGIF here or in iframe -->
        <!-- Copy & Pasted from YouTube -->
        <iframe width="560" height="349" [src]="vidUrl" frameborder="0" allowfullscreen></iframe>
    </div>
</div>

Please update me on whether this solution works for you. Good luck!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing precise data types for return values in React hooks with Typescript based on argument types

I developed a react hook that resembles the following structure: export const useForm = <T>(values: T) => { const [formData, setFormData] = useState<FormFieldData<T>>({}); useEffect(() => { const fields = {}; for (const ...

How can I properly include DefinitelyTyped TypeScript definition files in a .NET Core project?

Previously, under asp.net for .net framework, I utilized NuGet to incorporate TypeScript type definitions from third-party libraries (*.d.ts files) provided by DefinitelyTyped. However, with the shift to .NET Core, it seems that NuGet is no longer recommen ...

Waiting for completion of two observables in RxJS/Angular 11 while also managing errors

Currently, I am facing the challenge of waiting for two requests to complete (observables) and performing certain actions. Here is what I need: Wait for both requests (observables) to finish If one of them fails - show one error message If both of them f ...

The failure to build was due to the absence of the export of ParsedQs from express-serve-static-core

Encountered the error message [@types/express]-Type 'P' is not assignable to type 'ParamsArray'. Resolved it by installing specific packages "@types/express": "^4.17.8", "@types/express-serve-static-core": ...

How can I inform Typescript that an interface will exclusively consist of defined members?

My interface looks like this interface Person { name?:string; age? :number; gender?:string } I need to reuse the same interface type, but with a modification indicating that all members will never be undefined. The updated version would look like this: ...

There seems to be an issue with locating a differ that supports the object '[object Object]' of type 'object'. NgFor is only compatible with binding to Iterables like Arrays

My route.js const express = require('express'); const router = express.Router(); const University = require('../models/university'); var mongo = require('mongodb').MongoClient; var assert = require('assert'); va ...

Encountered a problem while attempting to build with ng build --prod. No issues when using ng serve or excluding

My project was working smoothly with ng build --prod until I decided to update the TypeScript version from 2.72 to 2.92 in my package.json file. Now, after the update, an error message pops up: ERROR in Cannot read property 'Symbol(Symbol.iterator ...

Error encountered when using Typescript with SvelteKit and Supabase data retrieval (Cannot assign type 'null' to type 'ArrayLike<unknown>')

My SvelteKit project is configured to authenticate with supabase. I followed this guide for the setup. Authentication and data fetching are working smoothly so far. However, I'm encountering a persistent Typescript error that I can't seem to reso ...

Creating a TypeScript mixin with a partial class is a useful technique that allows you to

I am attempting to have class A inherit properties from class B without using the extends keyword. To achieve this, I am utilizing a mixin in the following manner: class A{ someProp: String someMethod(){} } class B implements classA{ someProp: String ...

There is no such property - Axios and TypeScript

I am attempting to retrieve data from a Google spreadsheet using axios in Vue3 & TypeScript for the first time. This is my initial experience with Vue3, as opposed to Vue2. Upon running the code, I encountered this error: Property 'items' does ...

Using Typescript and Azure Functions to send FormData containing a file using Axios

I'm currently facing an issue with my Azure Function that handles file uploads to the endpoint. I am attempting to repost the files to another endpoint microservice using Axios, but I keep getting an error stating "source.on is not a function" when tr ...

Issue with ngStyle function in Internet Explorer

Within my Angular 4 application, I have defined styles as shown below: [ngStyle]="{'border': getInterleaveColor(i)}" The following function is also included: getInterleaveColor(auditNumber) { var borderProperties = '2px solid'; ...

Exploring nullish coalescing with undefined values

My function is set up to make API calls: interface getEventsPropsShape { eventId?: string; accountId?: string; eventsStartAfter?: string; } const getEvents = async ({ eventId, accountId, eventsStartAfter, }: getEventsPropsSha ...

Is there a way for me to retrieve the callback parameters?

Can the parameters of the callback function be accessed within the 'outer' function? function f(callback: (par1: string)=>void): void { // Is it possible to access 'par1' here? } ...

Troubleshooting a Custom Pipe Problem in Angular Material Drag and Drop

Currently, I am working on a project involving Angular Material Drag And Drop functionality. I have created a simplified example on StackBlitz which you can access through this link: here The project involves two lists - one containing pets and the other ...

Material Design Forms in Angular: A Winning Combination

I'm currently working on developing a form using Angular Material. This form allows the user to update their personal information through input fields. I am utilizing "mat-form-field" components for this purpose. However, there are certain fields tha ...

When we mention TypeScript and CDK, we are actually talking about the very foundation

As I was working on my current Stack constructor, I came across the Stack.formatArn() method. I started to wonder about the difference between using this.formatArn() and cdk.Stack.of(this).formatArn(). After all, shouldn't "this" refer to the stack it ...

The Angular 6 View does not reflect changes made to a variable inside a subscribe block

Why isn't the view reflecting changes when a variable is updated within a subscribe function? Here's my code snippet: example.component.ts testVariable: string; ngOnInit() { this.testVariable = 'foo'; this.someService.someO ...

Exploring Angular 2 Application Testing: Tips for Interacting with HTML Elements

In my Angular 2 Frontend testing journey, I came across a blog post ( ) where the author utilized ng-test TestBed for core testing in Angular. While the example provided was helpful for basic understanding, it lacked details on how to manipulate Elements. ...

Unable to invoke the AppComponent function within ngOnInit due to error message: "Object does not have the specified property or method"

I'm a novice in Angular and I am attempting to invoke my function setCenter2() from the AppComponent class within the ngOnInit function of the same class. Is this achievable? Whenever I try to call my function by clicking on the map (using OpenStreetM ...