Closed
Description
Bug Report or Feature Request (mark with an x
)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
macOS Sierra:
{ 'test-app': '0.0.0',
npm: '3.10.10',
ares: '1.10.1-DEV',
http_parser: '2.7.0',
icu: '58.2',
modules: '48',
node: '6.10.3',
openssl: '1.0.2k',
uv: '1.9.1',
v8: '5.1.281.101',
zlib: '1.2.11' }
Repro steps.
- Upgrade from version 1.0.1 to 1.1.3
npm run start
(which isng serve
)
The log given by the failure.
compiler.es5.js:1689 Uncaught Error: Can't resolve all parameters for providesGuard: (?).
at syntaxError (http://localhost:4200/vendor.bundle.js:18052:34)
at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver._getDependenciesMetadata (http://localhost:4200/vendor.bundle.js:32119:35)
at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver._getFactoryMetadata (http://localhost:4200/vendor.bundle.js:31999:51)
at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.getProviderMetadata (http://localhost:4200/vendor.bundle.js:32272:43)
at http://localhost:4200/vendor.bundle.js:32193:49
at Array.forEach (native)
at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver._getProvidersMetadata (http://localhost:4200/vendor.bundle.js:32153:19)
at http://localhost:4200/vendor.bundle.js:31728:63
at Array.forEach (native)
at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/vendor.bundle.js:31719:49)
Desired functionality.
Would like to know how to correct the ModuleWithProviders guard so that it's compatible going forward if this change in behavior between 1.0.1 and 1.1.3 is permanent. If it's a bug in 1.1.3, then a fix would be good. The work-around right now is to use 1.0.1.
Mention any other details that might be useful.
Here is a sanitized version of the module that reproduces the issue:
import {
NgModule,
ModuleWithProviders,
Inject,
InjectionToken,
SkipSelf,
Optional
} from '@angular/core';
// REST Service and Configuration
// IRestConfig is:
// export interface IRestConfig { port?: number; host?: string; apiUrl?: string; }
// REST_CONFIG is:
// export const REST_CONFIG = new InjectionToken<IRestConfig>('REST_CONFIG');
export { IRestConfig } from './shared/rest.config';
import { IRestConfig } from './shared/rest.config';
import { REST_CONFIG } from './shared/rest.service';
// Guard for providing RP
export const GUARD = new InjectionToken<void>('GUARD');
@NgModule({ })
export class TestModule {
static forRoot(config?: IRestConfig): ModuleWithProviders {
return {
ngModule: TestModule,
providers: [
{ provide: REST_CONFIG, useValue: config },
{
provide: GUARD,
useFactory: providesGuard,
deps: [
[ REST_CONFIG, new Optional(), new SkipSelf() ]
]
}
]
}
}
constructor(@Inject(GUARD) guard: any) { /** */ }
}
export function providesGuard(config: IRestConfig): any {
if (config) {
throw new Error('TestModule.forRoot() called twice.');
}
return 'guarded';
}
At the app module, one would add TestModule.forRoot({ port: 1234 })
, for example, into the imports
.
Changing from 1.0.1 to 1.1.3 of @angular/cli
results in the error (at the browser) that the argument to providesGuard
couldn't be resolved.
EDIT: Was missing code ticks ahead of the last block of code.