Establish a connection between an Angular 2 application and Google Cloud Endpoints

I am currently in the process of updating a web application from Angular 1 to Angular 2, and I'm facing challenges when it comes to integrating with Google Cloud Endpoints in my Angular 2 app.

I utilized the angular-cli to set up the Angular 2 project. My goal is to connect to the endpoints API from various services, so any guidance provided should take this into consideration.

Here's how I approached it in Angular 1:

In my index.html:

    <script>
        function init() {
            console.log("Initializing Cloud Endpoints..");
            window.init();
        };
    </script>        

    <script src="https://apis.google.com/js/client.js?onload=init"></script>

and in my main.js:

function Main($scope, $window){
    var vm = this;

    $window.init= function() {
        $scope.$apply(vm.loadApi);
    };

    vm.loadApi = function(){
        gapi.client.load('deviceStockApi', 'v1', function(){

            console.log("Cloud Endpoints are now available");

        }, 'https://name-of-my-endpoints-app.appspot.com/_ah/api');
    }
}   

Attempting the same in Angular 2:

Edit1: I'm currently focusing on getting the API to load initially, hence why all code is placed in the index.html file in the example below. However, ideally, I would prefer a more standardized solution for initiating and utilizing Cloud Endpoints within an Angular 2 application.

In my index.html:

<script src="https://apis.google.com/js/client.js?onload=init"></script>

<script>
  function init() {
    console.log("Init called");

    gapi.client.load('deviceStockApi', 'v1', function(){
      console.log("Cloud Endpoints are now available");
    }, 'https://name-of-my-endpoints-app.appspot.com/_ah/api');
  }
</script>

Upon running the web application, the init function is not triggered (no output in the console). Nonetheless, it appears that the script is being loaded.

https://i.sstatic.net/WFL80.png

If you have any suggestions on resolving this issue, your input would be greatly appreciated! Additionally, if you've come across any relevant documentation from Google or other sources on this topic, please feel free to share!

Answer №1

Have you experimented with changing the sequence of your actions in this scenario? Similar to how you handled Angular 1, consider placing the apis.google.com import after the init codeblock.

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

I encountered an issue with Svelte (Vite) + Bootstrap 5 + SvelteStrap where it gave me the error message stating: "Cannot assign type 'string' to type 'ButtonColor'"

I am currently working with Svelte (Vite) + Bootstrap 5 + SvelteStrap. The code I have written is as follows: <head> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_ ...

Encountering [Object Object] within an angular2 app

https://i.stack.imgur.com/iceKH.pngI recently created an angular2 application using ngrx/effects for handling http calls. My reference point was an application on GitHub. However, I am facing an issue where the response from the HTTP call is not displaying ...

Seeking guidance for the Angular Alert Service

I'm relatively new to using Angular and I'm struggling to determine the correct placement for my AlertService and module imports. Currently, I have it imported in my core module, which is then imported in my app module. The AlertService functions ...

Is it appropriate to incorporate existing cshtml markup from MVC into Angular 6?

I am currently working on a project that involves migrating an MVC application to Angular6. The designs for this project are already created in cshtml files, which are essentially views. My question is, would it be acceptable to use these existing designs ...

combine string inputs when ng-click is triggered

Is there a way to pass a concatenated string using ng-click to MyFunction(param: string)? I have tried but so far, no luck: <input id="MeasurementValue_{{sample.Number}}_{{$index}}" ng-click="Vm.MyFunction('MeasurementValue_{{sample.Number ...

Transmit: Forwarding information back to the recipient

My goal is to send an Http Post request (Registration form) using Angular, have it processed in the API, and if any errors occur like Please enter a username..., I want to return an error message to the client. Below is the Angular code for reference. Than ...

Using Angular2, you can easily implement property binding on child elements

Consider this basic Angular 2 application Primary component: @Component({ selector: "app" }) @View({ directives: [ChildComponent] template: '<child-component></child-component>' }) export class App {} Child component @ ...

Unleashed Breakpoint Mystery in Ionic 5 Angular with VSCode

I recently upgraded my Ionic 5 Angular 12 app from Ionic 4 Angular 8. The application is working well and remains stable, but I have encountered some issues while debugging. Firstly, when I use the launch.json file in Visual Studio Code to run the app, it ...

Guide to updating button appearance and behavior in Angular based on specific conditions

Need help with a button status issue in HTML. I am trying to display buttons based on the quantity received and total quantity using an if-else condition. However, the logic is not functioning correctly. Can someone assist? <div style="border-radius: 1 ...

Utilize Typescript Functions to Interact with GeoJSON Data in Palantir Foundry

Working on a map application within Palantir utilizing the workshop module. My goal is to have transport routes showcased along roads depending on user inputs. I am familiar with displaying a route using GeoJSON data, but I'm wondering if there is a w ...

Utilize Webpack to dynamically load specific angular-i18n locale files and minimize file overhead

Currently utilizing Webpack version 2.3.3 along with Babel-loader As a newcomer to Webpack, I am in the process of bundling angular-i18n locale files using Webpack. I have a configuration object that outlines the supported locales for the application: va ...

Determine the data type of an object's key

I have a XInterface defined as: export interface XInterface { foo: (() => Foo[]) | Foo[], bar: string, baz: number } When declaring an object using this interface, I want the type of foo to be Foo[], like so: const myObj: XInterface = { ...

Name cannot be located within the specified namespace

I am facing an issue with separating interfaces and implementations in TypeScript by utilizing the `module` feature. Despite using `<reference path=.../>`, I keep getting a "Cannot find name" error in my code. Below is an example: IUserService.ts n ...

Alert: TypeScript Linter Warning

When I execute the npm lint command in Circle CI, a warning message is displayed. The following rules specified in the configuration could not be found: templates-use-public no-access-missing-member invoke-injectable template-to-ng-templa ...

A method for comparing two arrays containing identical objects and then storing the results in a variable

I have an item stored within two other items called formKeyValues and form formKeyValues https://i.stack.imgur.com/nRfiu.png form https://i.stack.imgur.com/eDpid.png I am looking to extract only the keys and values from formKeyValues and place them in ...

Discover the unique value in Angular if it is not present in the list

I have a question about handling values in a list and displaying the "create value" component to the user when needed. How can I efficiently compare search input values with those in the list and determine if a match exists? If no match is found, the "cr ...

Creating a backup link for a video player component in NextJs

My aim is to make sure that two video player components in a NextJS application can still access and play videos even when the application is running locally using npm run dev without an internet connection. Currently, these two components.. <HoverVi ...

Exploring the correct navigation of page objects through Protractor using TypeScript

I'm working on setting up a protractor test suite with TypeScript and running into an issue involving chaining of pageObjects for multiple pages. I haven't seen any examples that deal with this specific scenario. I've simplified the example ...

Managing Access Control Origin Headers in an Angular 4 Application

I currently have a Play framework based REST API running locally on port 9000 of my machine. Additionally, I have an Angular 4 application running on port 4200 on the same localhost. My goal is to have this Angular app display the JSON data received from ...

Is there a way in Typescript to dynamically create a type based on an array of potential values?

I am seeking a solution to dynamically define a type based on an array of possibilities. Within the provided map, the keys represent the type's name, while the corresponding values are arrays containing possible options for that type. export const ty ...