You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new to Maui and Maui Blazor development, and I know that in a project where Blazor WASM and Maui Blazor share UI, to reference some js packages you need to look like follows:
/*
* Let's say we have a JavaScript file called a.js and it have a function called sayHello to print Hello into console
* /
@page "/hello"@usingMicrosoft.JSInterop;
<h3>Hello Test</h3>
@code{
[Inject]
IJSRuntimeJSRuntime{get; set; }Lazy<Task<IJSObjectReference>>ImportTask;
protectedoverridevoidOnInitialized()
{ImportTask=newLazy<Task<IJSObjectReference>>(JSRuntime.InvokeAsync<IJSObjectReference>("import", newobject?[] { "./_content/PackageID/Sub_Dirs_In_wwwroot/filename" }).AsTask());
}protectedoverrideasyncTaskOnAfterRenderAsync(boolfirstRender)
{IJSObjectReferenceJSObject;
if (firstRender)
{
JSObject=awaitImportTask.Value;
}
awaitJSObject.InvokeVoidAsync("sayHello",newobject?[] { });
}}
Then now the gameplay has been upgraded, I'm trying to render a chart with ECharts in Blazor WASM and Maui Blazor, because ECharts are a bit more complicated for me, So I want to use TypeScript instead of JavaScript(thanks to TypeScript's strong typing support). However, I have a headache when using ECharts packages in TypeScript. In the following code, importing ECharts packages using the previous two lines will prompt TS2307 to find the module or its corresponding type declaration error. Importing ECharts using lines 4 and 5 returns an Http 404 error when retrieving the charts.js file
//import * as echarts from './_content/BlazorCharts.Core/node_modules/echarts/index'//import { BarSeriesOption, EChartsType } from './_content/BlazorCharts.Core/node_modules/echarts/index';import*asechartsfrom'../node_modules/echarts/index'import{EChartsType}from'../node_modules/echarts/index'constinitChart=function(element: HTMLDivElement): EChartsType{returnecharts.init(elementasHTMLElement)}export{initChart}
Am I using something wrong? How can I properly use TypeScript in projects where Blazor and Maui Blazor share UI?
linechart.ts
This file is located under the BlazorCharts.Core project
//import * as echarts from './_content/BlazorCharts.Core/node_modules/echarts/index'//import { BarSeriesOption, EChartsType } from './_content/BlazorCharts.Core/node_modules/echarts/index';import*asechartsfrom'../node_modules/echarts/index'import{EChartsType}from'../node_modules/echarts/index'constinitChart=function(element: HTMLDivElement): EChartsType{returnecharts.init(elementasHTMLElement)}export{initChart}
HelloTest.razor
This file is located under the BlazorCharts.Shared
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there!
I am new to Maui and Maui Blazor development, and I know that in a project where Blazor WASM and Maui Blazor share UI, to reference some js packages you need to look like follows:
Then now the gameplay has been upgraded, I'm trying to render a chart with ECharts in Blazor WASM and Maui Blazor, because ECharts are a bit more complicated for me, So I want to use TypeScript instead of JavaScript(thanks to TypeScript's strong typing support). However, I have a headache when using ECharts packages in TypeScript. In the following code, importing ECharts packages using the previous two lines will prompt TS2307 to find the module or its corresponding type declaration error. Importing ECharts using lines 4 and 5 returns an Http 404 error when retrieving the charts.js file
Am I using something wrong? How can I properly use TypeScript in projects where Blazor and Maui Blazor share UI?
linechart.ts
HelloTest.razor
Beta Was this translation helpful? Give feedback.
All reactions