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
Copy file name to clipboardExpand all lines: aspnetcore/blazor/javascript-interoperability/call-javascript-from-dotnet.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -462,8 +462,8 @@ IJSRuntime JS { get; set; }
462
462
463
463
Create an instance of a JS object using a constructor function and get the <xref:Microsoft.JSInterop.IJSObjectReference>/<xref:Microsoft.JSInterop.IJSInProcessObjectReference> .NET handle for referencing the instance with the following API:
464
464
465
-
*`InvokeNewAsync`
466
-
*`InvokeNew`
465
+
*`InvokeNewAsync` (asynchronous)
466
+
*`InvokeNew` (synchronous)
467
467
468
468
Examples in this section demonstrate the API calls with the following `TestClass` with a constructor function (`constructor(text)`):
469
469
@@ -512,8 +512,8 @@ An overload is available that takes a <xref:System.Threading.CancellationToken>
512
512
513
513
Read or modify the value of a JS object property, both data and accessor properties, with the following API:
514
514
515
-
*`GetValueAsync`/`SetValueAsync`
516
-
*`GetValue`/`SetValue`
515
+
*`GetValueAsync`/`SetValueAsync` (asynchronous)
516
+
*`GetValue`/`SetValue` (synchronous)
517
517
518
518
Examples in this section demonstrate the API calls with the following JS object (`testObject`):
Copy file name to clipboardExpand all lines: aspnetcore/release-notes/aspnetcore-10/includes/blazor.md
+8-9Lines changed: 8 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,11 +292,10 @@ Blazor adds support for the following JS interop features:
292
292
293
293
The following asynchronous methods are available on <xref:Microsoft.JSInterop.IJSRuntime> and <xref:Microsoft.JSInterop.IJSObjectReference> with the same scoping behavior as the existing <xref:Microsoft.JSInterop.IJSRuntime.InvokeAsync%2A?displayProperty=nameWithType> method:
294
294
295
-
* `InvokeNewAsync(string identifier, object?[]? args)`: Invokes the specified JS constructor function asynchronously. The function is invoked with the `new` operator. In the following example, `jsInteropTests.TestClass` is a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSObjectReference>:
295
+
* `InvokeNewAsync(string identifier, object?[]? args)`: Invokes the specified JS constructor function asynchronously. The function is invoked with the `new` operator. In the following example, `jsInterop.TestClass` is a class with a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSObjectReference>:
296
296
297
297
```csharp
298
-
var classRef = await JSRuntime.InvokeNewAsync("jsInteropTests.TestClass",
299
-
"text value");
298
+
var classRef = await JSRuntime.InvokeNewAsync("jsInterop.TestClass", "Blazor!");
300
299
var text = await classRef.GetValueAsync<string>("text");
301
300
var textLength = await classRef.InvokeAsync<int>("getTextLength");
302
301
```
@@ -305,13 +304,13 @@ The following asynchronous methods are available on <xref:Microsoft.JSInterop.IJ
305
304
306
305
```csharp
307
306
var valueFromDataPropertyAsync = await JSRuntime.GetValueAsync<int>(
308
-
"jsInteropTests.testObject.num");
307
+
"jsInterop.testObject.num");
309
308
```
310
309
311
310
* `SetValueAsync<TValue>(string identifier, TValue value)`: Updates the value of the specified JS property asynchronously. The property can't be a `get`-only property. If the property isn't defined on the target object, the property is created. In the following example, `num` is created on `testObject` with a value of 30 if it doesn't exist:
Overloads are available for each of the preceding methods that take a <xref:System.Threading.CancellationToken> argument or <xref:System.TimeSpan> timeout argument.
@@ -320,11 +319,11 @@ The special overload `IJSObjectReference.GetValueAsync<TValue>()` doesn't take a
320
319
321
320
The following synchronous methods are available on <xref:Microsoft.JSInterop.IJSInProcessRuntime> and <xref:Microsoft.JSInterop.IJSInProcessObjectReference> with the same scoping behavior as the existing <xref:Microsoft.JSInterop.IJSInProcessObjectReference.Invoke%2A?displayProperty=nameWithType> method:
322
321
323
-
* `InvokeNew(string identifier, object?[]? args)`: Invokes the specified JS constructor function synchronously. The function is invoked with the `new` operator. In the following example, `jsInteropTests.TestClass` is a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSInProcessObjectReference>:
322
+
* `InvokeNew(string identifier, object?[]? args)`: Invokes the specified JS constructor function synchronously. The function is invoked with the `new` operator. In the following example, `jsInterop.TestClass` is a class with a constructor function, and `classRef` is an <xref:Microsoft.JSInterop.IJSInProcessObjectReference>:
324
323
325
324
```csharp
326
325
var inProcRuntime = ((IJSInProcessRuntime)JSRuntime);
327
-
var classRef = inProcRuntime.InvokeNew("jsInteropTests.TestClass", "text value");
326
+
var classRef = inProcRuntime.InvokeNew("jsInterop.TestClass", "Blazor!");
328
327
var text = await classRef.GetValueAsync<string>("text");
329
328
var textLength = await classRef.InvokeAsync<int>("getTextLength");
330
329
```
@@ -334,14 +333,14 @@ The following synchronous methods are available on <xref:Microsoft.JSInterop.IJS
334
333
```csharp
335
334
var inProcRuntime = ((IJSInProcessRuntime)JSRuntime);
336
335
var valueFromDataProperty = inProcRuntime.GetValue<int>(
337
-
"jsInteropTests.testObject.num");
336
+
"jsInterop.testObject.num");
338
337
```
339
338
340
339
* `SetValue<TValue>(string identifier, TValue value)`: Updates the value of the specified JS property synchronously. The property can't be a `get`-only property. If the property isn't defined on the target object, the property is created. In the following example, `num` is created on `testObject` with a value of 20 if it doesn't exist:
341
340
342
341
```csharp
343
342
var inProcRuntime = ((IJSInProcessRuntime)JSRuntime);
0 commit comments