angular4.0 ERROR Error: Uncaught (in promise): Error: No provider for AuthGuard! Error: No provider

使用angular4.0,开发路由守卫的时候,报一下错误

ERROR Error: Uncaught (in promise): Error: No provider for AuthGuard!
Error: No provider for AuthGuard!

1、首先确认,在文件中,已经加载

import { AuthGuard } from '../auth-guard.service';


const adminRoutes: Routes = [
	{
		...
		canActivate: [AuthGuard],
		...
	}
]
2、接着确认,在app.module.ts中将AuthGuard引入到providers
import { AuthGuard } from './auth-guard.service';

@NgModule({
	...
	providers: [
		...
		AuthGuard
	]
})


前端交流群:468103283

你可能感兴趣的