Saturday, July 14, 2018

Necessary Modules in Ionic

npm install @angular/router --save

A lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.

https://www.npmjs.com/package/moment

Fancy date ranges for Moment.js.
https://www.npmjs.com/package/moment-range

Role-based permissions for AngularJS 2
https://www.npmjs.com/package/angular2-acl


https://www.npmjs.com/package/socket.io-client

Troubleshooting


  1. Operator '!==' cannot be applied to types '"string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"' and '"String"


 private _parseParam(key: string, value: any, parent: string) {
        if (typeof value !== 'object') && (typeof value !== 'array') {
            return parent ? parent + '[' + key + ']=' + value
                          : key + '=' + value;
        } else if (typeof value === 'object' ||  typeof value === 'array') {
            return parent ? this._JSON2URL(value, parent + '[' + key + ']')
                          : this._JSON2URL(value, key);
        } else {
            throw new Error('Unexpected Type');
        }

    }

Solution:


private _parseParam(key: string, value: any, parent: string) {
        let typeofValue:string = typeof value;

        if (typeofValue !== 'object' && typeofValue !== 'array') {
            return parent ? parent + '[' + key + ']=' + value
                          : key + '=' + value;
        } else {
            return parent ? this._JSON2URL(value, parent + '[' + key + ']')
                          : this._JSON2URL(value, key);
        }
    }

  1. “No provider for TranslateService” error somehow connected to npm install

You have to import TranslateModule.forRoot() in the root NgModule of your application.
app.module.ts:
@NgModule({
  imports: [
    //...
    TranslateModule.forRoot(),
  ],
  //...
})
Or if you're using a SharedModule:
If you use a SharedModule that you import in multiple other feature modules, you can export the TranslateModule to make sure you don't have to import it in every module
@NgModule({
  exports: [
    //...
    TranslateModule,
  ],
  //...
})

StaticInjectorError

Error: Uncaught (in promise): Error: StaticInjectorError[LocalStorageService]:
Cause: Tried to use a service without declaring the service in providers under app.module.ts
Translate Service
https://blog.thecodecampus.de/ionic2-angular2-translate-internationalize-localize-app/