Rendering for AoT compilation

I had some issues with inconsistencies between JIT and AoT compilers . The very last mistake that hit me was Error: Can't resolve all parameters for IndexedDBCache

. IndexedDBCache is a service that depends on a parameter string

:

Note that this problem also occurs when I remove the "protected" property!

// indexeddb-cache.ts
import { Injectable } from '@angular/core';

@Injectable()
export class IndexedDBCache {
  constructor(protected databaseName : string) {}
}

      

I am using a factory to provide versions of a service:

// test-api.cache.factory.ts
import { IndexedDBCache } from '../indexeddb-cache/indexeddb-cache';

export function testIndexedDBCacheFactory() { return new IndexedDBCache('test'); }

// test-api.cache.ts
import { InjectionToken, Provider } from '@angular/core';
import { IndexedDBCache } from '../indexeddb-cache/indexeddb-cache';
import { testIndexedDBCacheFactory } from './test-api.cache.factory';

export const testIndexedDBCache = new InjectionToken<IndexedDBCache>('testIndexedDBCache');

export let testIndexedDBCacheProvider : Provider = {
  provide: testIndexedDBCache,
  useFactory: testIndexedDBCacheFactory
};

      

Note. These files should be split according to func-in-providers-useFactory and arrow-function-exports - don't ask me why = /

Now the AoT compiler doesn't like this option at all string

. I looked into this question but could only find a link to OpaqueToken

(now stripped and replaced with InjectionToken<string>

). My code will now read:

// test-api.cache.factory.ts
import { InjectionToken } from '@angular/core';
import { IndexedDBCache } from '../indexeddb-cache/indexeddb-cache';

const testIndexedDBCacheFactoryToken = new InjectionToken<string>('test');
export function testIndexedDBCacheFactory() { return new IndexedDBCache(testIndexedDBCacheFactoryToken); }

      

Obviously this is not compilation, as the constructor only accepts a parameter string

. I don't have enough knowledge of InjectionTokens or AoT issues to solve this problem - who has a suggestion for a construct that will work?

More context for my code and question can be found at angular / angular # 17295 .


Things I've tried:

  • Remove Access Modifier protected

    > Exact error is saved
  • Remove string parameter> Not an option - it defines a service
  • Replacing string parameter in factory with InjectionToken<string>

    > An InjectionToken is not an appropriate parameter
+3


source to share


1 answer


There was a lack of understanding of this problem. The classes to be factorized are not the services themselves and therefore do not need the property @Injectable

. More information can be found in Building Compatible AoT Services



+2


source







All Articles