import self executing function to another class in typescript

Andrei

I am doing Hybrid AngularJS/Angular5 application. So I am trying step by step change my JavaScript files to Typescript. I had javascript file :

(function () {
    'use strict';

    var domainPath = "http://localhost:26264/";
    var reportAPI = "http://localhost:58629/";
    var onlineHelpURL = "http://localhost:8085/";
    var hh6ServiceUrl = "https://localhost:40100/";

    var sysSettings = {
        webServiceURL: domainPath,
        hh6ServiceUrl: hh6ServiceUrl,
        reportServiceURL: reportAPI,
        onlineHelpURL: onlineHelpURL
    };

    angular.module('app.sysSettings', []).constant("sysSettings", sysSettings);
})();  

and I changed it in typescript to be able to export it and reuse settings in my typescript files :

declare var angular: any;

let sysSettingsts = (function () {
    'use strict';
    var domainPath = "http://localhost:26264/";
    var reportAPI = "http://localhost:58629/";
    var onlineHelpURL = "http://localhost:8085/";
    var hh6ServiceUrl = "http://localhost:40100/";
    var sysSettings: any = {
        webServiceURL: domainPath,
        hh6ServiceUrl: hh6ServiceUrl,
        reportServiceURL: reportAPI,
        onlineHelpURL: onlineHelpURL
    };

    angular.module('app.sysSettings', []).constant("sysSettings", sysSettings);

    return sysSettings;
})();

export default sysSettingsts;

But when I am trying to import that file :

import { Injectable } from '@angular/core';
import { TranslateLoader } from '@ngx-translate/core';
import { Observable } from 'rxjs/Observable';
import {HttpClient} from "@angular/common/http";
import {sysSettingsts} from "angular/sysSettings";

@Injectable()
export class CustomTranslateLoader implements TranslateLoader  {

  constructor(private http: HttpClient,
              private item: sysSettingsts) {
    this.item = item;
  }

  getTranslation(lang: string): Observable<any>{

var apiAddress = this.item.domainPath + "api/GlobalResources/?lang=" + lang;
return Observable.create(observer => {
  this.http.get(apiAddress, ).subscribe(res => {
      observer.next(res);
      observer.complete();
    },
    error => {
      console.log("cannot retrieve Global Resources");
    }
  );
});

}

I am able to see only values in import {sysSettingsts} from "angular/sysSettings"; file but insight constructor my sysSettingsts is undefined.

  constructor(private http: HttpClient,
              private item: sysSettingsts) {
    this.item = item;
  }

I tried to use sysSettingsts directly inside the method but the value is undefined too... Could please anyone give me a hind how can I export executing a function in typescript or at least give some idea how can I import settings from my typescript file in another typescript files (make settings reusable).

Thanks

CRice

Change either your export or import syntax. Right now they don't match.

When using a default export:

export default sysSettingsts;

The corresponding import syntax is:

import sysSettingsts from "angular/sysSettings"

Note the lack of braces.


Or, if you want to maintain the same import syntax, then use the regular (non default) export instead:

export { sysSettingsts }

You can read more about the import/export pattern here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to call self executing function from another file

Self executing function inheritance

Passing self from a member function to a function in another class

jQuery self executing function not fireing

Self Executing Function in Constructor Pattern

Is parameter in self executing function necessary?

Add function to class from another file in Typescript

ES6 self executing import

Call a class function in a self in another function so that the attributes only include one and the variable not included but is self function?

Typescript class export from one module and import in another

How would I attach self to another module's function/class?

typescript import function from another ts file - file is not a module error

How can I import my API function to another Typescript file?

Typescript - Self-Executing Anonymous Functions

How to correctly wait for async function to finish before executing another function in typescript?

typescript import dependency with class

Why import class from another file will call __init__ function?

useState executing before another function

self executing function jquery vs javascript difference

onClick on fires once in self executing function jQuery

What is the purpose of a self executing function in javascript?

difference between self executing function and IIFE

JavaScript: Self-executing function with parameter

Import a int to a another class

Typescript import class to service class

Typescript and Jquery import - $ is not a function

TypeScript export/import function

Typescript - Import Namespace Into Another Namespace

TypeScript class is turning into another class