I am trying to connect my ionic 4 app ( angular 7 ) with azure iot hub.I am trying to send msgs from my app to iot hub. Downloaded "azure-iothub" inside my ionic project and trying to import "client" to form connection but while building getting errors .
Tried setting these specific modules false for browser , it builds with warnings but app doesn't load on localhost. Also tried http post request but there also getting CORS error as " localhost is not allowed to access ".
import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import {Client} from 'azure-iothub';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar
) {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
});
var connectionString = '**********';
var client = Client.fromConnectionString(connectionString);
client.open(function (err) {
if (err) {
console.error('Could not connect: ' + err.message);
} else {
console.log('Service client connected');
}});
}
}
Getting the following error- error while building