Tips and tricks for utilizing window.external in Angular 2

I am trying to implement a call from window.external in Angular 2 and pass a JSON as a parameter.

Here is an example similar to what I am trying to achieve:

C#

[System.Runtime.InteropServices.ComVisibleAttribute(true)]
   public class ScriptInterface
   {
      void callMe(string json)
      {
       … // Do something interesting
      }
   } 

   webBrowser1.ObjectForScripting = new ScriptInterface();

Angular 2

window.external.callMe(json);

Does anyone have any tips or suggestions on how to accomplish this?

Thank you

Answer №1

To accomplish this, one approach is through event handling:

  • Create an event in your external function

  • Have your Angular application listen for this event and respond accordingly (for instance, by notifying a service that will then notify the necessary components which have subscribed to it, or by utilizing a HostListener directive)

For a specific example:

or

Detect Click outside element in angular 4 using directives

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

Loading an ASP.NET page dynamically from a DLL

My vision is to develop a modular ASP.NET application that functions as a module loader within a main application. The main application would consist of a single "Default.aspx" page which dynamically generates a menu and links based on the modules loaded i ...

Class with an undefined function call

Currently, I am working with angular2 and TypeScript where I have defined a class. export class Example{ //.../ const self: all = this; functionToCall(){ //.. Do somerthing } mainFunctionCall(){ somepromise.then(x => self.fu ...

There was a problem while compiling the requested file or one of its dependencies. A semicolon is expected

I am currently attempting to format this JSON in order to assign it to DataProviderJSON correctly. However, I keep encountering an error related to the variable 'testing': During the compilation of the requested file or one of its dependencies, ...

After updating my NuGet packages, I encountered the error message: "The authority that issued the certificate chain is not trusted."

I am facing an issue with one of my API projects called WorkerService. When I try to connect, it throws the following warning: Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error ...

Execute automation tasks by running multiple instances of Chrome with different profiles

My goal is to simultaneously run multiple instances of Chrome with different profiles, each having their own cookies, to perform various tasks. For example, I want to search on Google using 2 separate accounts, each with its own proxy settings. I am curre ...

VS Code is throwing an Error TS7013, while Typescript remains unfazed

In my Typescript/Angular project, I have the following interface: export interface MyInterface { new (helper: MyInterfaceHelpers); } After compiling the project, no errors are shown by the Typescript compiler. However, VSCode highlights it with squiggl ...

Angular ngFor directive is used to iterate over a collection and display each record

Hey there! I am currently facing an issue where the data array is displaying on the console, but only one record is being displayed in the view. users: any[]=[]; ngOnInit(): void { this.loadUsers(); } loadUsers() { let controller = this; t ...

A step-by-step guide on sending emails through SMTP in ASP.NET

I am encountering an error and need a solution for it. When running the program, I encountered the following error: "Send Email Failed. The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must i ...

Tips for implementing filters in Angular2 without using the package field in the console

I am currently experiencing an issue with a filter field in my code. The filter works fine when all the package data is present, however, some items do not have a package field. As a result, I need to filter based on the package name but I am encountering ...

Convert a collection of observables containing events to an observable array of events

I am working on creating a function that merges all event streams generated from an array of data channels and emits any event received from them. Below is the initial function: private dataChannels: BehaviorSubject<RTCDataChannel[]> = new Behavi ...

Guide on integrating a Jison generated parser within an Angular application

Using the Jison library, parsers can be created based on a specific grammar by running: $ jison calculator.jison This process is described in reference [1]. The above command generates a parser named calculator.js. Now the question arises - how to in ...

What is the syntax for creating multi-line function definitions in TypeScript?

When it comes to writing functions with numerous parameters, do you typically format them like this: function foo( a: number, b: string, c: boolean): boolean { .... } or do you prefer formatting them like this: function foo( a: number, ...

Utilizing TypeScript 3.1: Easier Array Indexing with Enums in Strict Mode

Enabling TypeScript "strict" mode with "noImplicitAny" causes this code to fail compilation. I am looking for guidance on how to properly declare and use Arrays indexed by Enum values. namespace CommandLineParser { enum States { sNoWhere, sSwitchValu ...

Ng2-smart-table: Utilizing Angular 2 for Efficient Data Organization with Identically Named Columns

Here is a snippet of code where I am trying to display columns from a table: products: { title: 'Prodotto', filter: false, class: "colonneTabella", width: "15%", ...

"Encountering a 404 Error when attempting to refresh an Angular 13 application hosted on an Apache

I have developed a prototype web application and now need to deploy it on an Apache server running Ubuntu OS. After building the web app, I hosted it on my local machine for testing purposes. I have configured the .htaccess file as follows: RewriteEngine ...

The occurrence of "xyz" member in the code is inferred to have an unspecified "any" type, resulting in an error when utilizing react with typescript

I'm currently utilizing the React useForm hook along with typescript for validation. I have set up setError, clearError, and created specific types for it. However, I've encountered an error stating "Member 'xyz' implicitly has an &apos ...

Cosmic Plantation Matrix Classification Or Arrangement

I am currently utilizing angular 9 along with Nebular v6.1.0 in my project. One issue I have encountered is related to filtering and sorting data displayed using the nebular TreeGridComponent. When dealing with basic data types such as strings or numbers, ...

Creating typed props is important when utilizing the Material UI makeStyles function

Currently, I'm in the process of transitioning some of my React components to the latest makeStyles/useStyles hook API from Material UI. As far as I know, I can still accept classes as a prop from parent components by passing the props to useStyles: ...

I am looking for a way to convert the date format from "yyyy-MM-dd" to "dd-MM-yyyy" in NestJs

I need help with changing the date format from "yyyy-MM-dd" to "dd-MM-yyyy". Currently, my entity code looks like this: @IsOptional() @ApiProperty({ example: '1999-12-12', nullable: true }) @Column({ type: 'date', nullable: true } ...

Methods for Expiring a Session Upon Page Refresh in Angular4

Is there a way to invalidate the session and automatically redirect to the login page when the browser's refresh button is clicked? I attempted to achieve this using @HostListener, but the page redirects to the login and then returns to the same page. ...