aspnetcore-angular-universal icon indicating copy to clipboard operation
aspnetcore-angular-universal copied to clipboard

How to access the domain out of class AppModuleShared in app.module?

Open GetTaxSolutions opened this issue 7 years ago • 2 comments

Hello,

I want to get the domain out of class and can't inject it in some constructor. How I can get the domain? The case is: In app.module.ts I have to set one config object which have to be set in imports -> NgcCookieConsentModule.forRoot(cookieConfig) which is the part of class decorator. So I want to have the object before class declaration and add this code: const cookieConfig: NgcCookieConsentConfig = { "cookie": { "domain": ${ORIGIN_URL} }, "palette": { "popup": { "background": "#efefef", "text": "#404040" }, "button": { "background": "#8ec760", "text": "#ffffff" } }, //"type": "opt-out", "theme": "classic", //'edgeless', "position": "bottom-right" }; But ORIGIN_URL is injector and I haven't access to the domain.

How I can access the domain in this case?

Thank you GetTaxSolutions

GetTaxSolutions avatar Nov 30 '17 08:11 GetTaxSolutions

We need to see how your code is actually setup, in full... I can't really gather much from what you have described here... My only suggestion I can come up with, is to replace ${ORIGIN_URL} with just plain old ORIGIN_URL as, that text is actually just a variable, that you can throw into places... For an example, see how it is used in the TranslateModule: image

Adondriel avatar Dec 21 '17 20:12 Adondriel

In app.module.ts

const cookieConfig: NgcCookieConsentConfig = 
  {
    "cookie": {
      "domain":  `${ORIGIN_URL}`
    },
  "palette": {
    "popup": {
      "background": "#efefef",
        "text": "#404040"
    },
    "button": {
      "background": "#8ec760",
        "text": "#ffffff"
    }
    },
  "theme": "classic",
    "position": "bottom-right"
  };

console.log("===========AppModuleShared===============");
console.log(JSON.stringify(cookieConfig));
console.log("===========End AppModuleShared===============");
.....
@NgModule({
....
imports: [
NgcCookieConsentModule.forRoot(cookieConfig),
.....
]
})
export class AppModuleShared {
}

The result in console is: {"cookie":{"domain":"InjectionToken ORIGIN_URL"},"palette":{"popup":{"background":"#efefef","text":"#404040"},"button":{"background":"#8ec760","text":"#ffffff"}},"theme":"classic","position":"bottom-right"}

The domain property is not actually domain name. How I can get the domain and pass it here? That was my question.

GetTaxSolutions avatar Jan 01 '18 14:01 GetTaxSolutions