Skip to content

Bad identifier in the example #34034

@wujido

Description

@wujido

Description

File wwwroot/scripts.js from the example of Blazor component initialization from js looks like this


Copy
window.showQuote = async () => {
  let targetElement = document.getElementById('quoteContainer');
  await Blazor.rootComponents.add(targetElement, 'quote', 
  {
    text: "Crow: I have my doubts that this movie is actually 'starring' " +
      "anybody. More like, 'camera is generally pointed at.'"
  });
}

const btn = document.querySelector("showQuoteBtn");
btn.addEventListener("click", showQuote);

This line const btn = document.querySelector("showQuoteBtn"); does not contain identifier that would match later presented html, # is missing. Correct version should look like this const btn = document.querySelector("#showQuoteBtn");

Page URL

https://learn.microsoft.com/en-us/aspnet/core/blazor/components/js-spa-frameworks?view=aspnetcore-8.0#render-razor-components-from-javascript

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/components/js-spa-frameworks.md

Document ID

444b03b4-f910-656a-642c-6c9064d6ce28

Article author

@guardrex

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions