Questions tagged [angular2-opaquetoken]

7 questions
38
votes
4 answers

What is in Angular 2 Opaque Token and What's the Point?

I am running into 'opaque tokens' as a solution to implementing global constants in Angular 2, for example here: Define global constants in Angular 2 Despite reading the docs, I can't seem to grasp the point. Using an OpaqueToken is preferable to…
VSO
  • 11,546
  • 25
  • 99
  • 187
7
votes
1 answer

Using injectable token for handling global constants Angular 4

we are building new Angular 4 project and trying to understand what approach will be the best for handling global constants which will be reused through all project. I want to place all constants inside shared folder like so shared --constants …
VladosJS
  • 1,210
  • 8
  • 20
2
votes
0 answers

Why use a Service and Token / OpaqueToken to get the Window object in Angular

I was speaking to a colleague the other day who didn't like my code. In my Angular Component I access the window object like so private myWindow = window; He told me a better way was to use a Service and a Token / OpaqueToken (I have no idea what a…
Mark Sandman
  • 3,293
  • 12
  • 40
  • 60
1
vote
0 answers

How to import 3rd party js libraries into angular with the aot compiler

I am currently using an opaque token. I first define an opaque token in the common section of the project as follows: import { InjectionToken } from '@angular/core'; export let JQ_TOKEN = new InjectionToken('jQuery'); I then import this as…
trees_are_great
  • 3,881
  • 3
  • 31
  • 62
0
votes
1 answer

Angular: Inject an opaque token

I try to understand how I could inject an opaque token. For instance, I have some service MyService, and I create an opaque token for it: import {OpaqueToken} from '@angular/core'; ... const serviceToken = new…
Mike Mameko
  • 199
  • 1
  • 2
  • 11
0
votes
1 answer

Angular2 Routing-Resolve interface usage with OpaqueToken

I want to fetch data before an route/component is instantiated. Therefore I want to use the "Resolver"-Interface from the Angular2-Routing-Module. Take a look at my code. Its working with a string as the provider name, but throwing errors if I use…
0
votes
0 answers

OpaqueTokens - why do they require @Inject(token) instead of being typed

Why do I need to @Inject(...) an OpaqueToken, instead of using it like a type? Why does this work: import { AppConstantsToken } from './app.constants.ts'; export class MyApp { constructor(@Inject(AppConstantsToken) private config) { …
keldar
  • 6,152
  • 10
  • 52
  • 82