04-21-2020 03:30 PM
Hello,
I would like to use Angular for development with the COBI.Bike DevKit. As per documentation this is possible but I have not managed to get any real time data. What I've done is the following:
- Included COBI.js in index.html via script tag.
- Declare COBI as a variable and include via custom type definition
- I want to wrap the COBI API inside an Angular service later but for now I've initialized COBI using COBI.init('token') inside the Angular component and subscribed to COBI.rideService.speed and wanted to update the according variable in the template.
What happens is that there is no real time data as in the examples. The current speed data only get's displayed when I reload the browser, and this actually only works sometimes. I've already tried to initialize COBI in an Angular app initializer to be sure that COBI is definetly initialized before accessing the API. That also does not change the described behaviour.
I have already seen that all the example applications use plain JavaScript. Is this really the only way to use COBI.js?
Solved! Go to Solution.
04-21-2020 05:17 PM
Hello divid3byzero,
Thank you for your question and your interest in the COBI.Bike SDK.
It is definitely possible to use Angular and our Devkit together. Could you please tell me which version of Angular are you using? Is it Angular.js (version 1.x) or "Angular.io" (version 2 and higher).
In the case of Angular.io, we have found that it helps to start the main file, probably your main.ts, with the following line:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
Let us know if that worked!!
04-21-2020 10:17 PM - edited 04-21-2020 10:18 PM
Hello,
thank you for your quick answer. I using Angular (version 9.1.1) not Angular.js. Your suggestion to add the plattformBrowserDynamic import to the top of the main.ts did not help. I can see logging output of Cobi data which very probably comes from the devkit, so it seems to be basically working.
I've set up a basic Angular demo project on GitHub for you to look at to illustrate how I set up the application: https://github.com/divid3byzero/ng-cobi-demo
Sidenote: I noticed that the logging output on the console says the following on initially loadinig the application:
COBI.init failed. Retrying in 500 milliseconds
The next init is successful. I don't think that that has anything to do with my problem but I am still wondering why this is happening. I've also experienced an issue with the module "MyModule" that was added to the Cobi app after registering as a developer. But I guess I'd best open another thread for that.
04-23-2020 08:48 AM
Is there any news on this?
05-08-2020 11:35 AM
Hello divid3byzero,
Sorry for the late reply.
With regards to the message you mention, this is the normal behaviour. Our Javascript framework tries to connect with the COBI.Bike app every 500ms until it gets a success message from the system. Since it usually takes a few seconds to establish this connection, it is normal to see a few of this messages when you start your module
COBI.init failed. Retrying in 500 milliseconds
Best regards,