将我的应用程序更新为angular2到RC4后我收到此错误。我已在LoginService
新webpack starter包中注入了AppComponent
。
我试图在路线中包含AppComponent
,但它不会起作用。
另外我在index.ts中包含了LoginService
和APP_PROVIDERS,但我收到了另一个错误
无效的提供者 - 仅允许提供者和类型的实例, 得到:未定义
同时将LoginService
置于引导程序中,但不起作用。
RC4中Angular2有什么问题?组件不再在树中了?
这是路由器的路由器配置" 3.0.0-beta.2" :
export const routes: RouterConfig = [
{ path: '', component: StartPageComponent },
{ path: 'login', component: StartPageComponent },
{
path: 'dashboard', component: 'DashboardComponent',
canActivate: [WebpackAsyncRoute],
children: [
{ path: '', component: 'ContentDesktopComponent' } // must be included
]
},
{ path: '**', component: NoContent }
];
我想为每条路线提供LoginService。
我的app.component看起来像这样:
@Component({
selector: 'app',
pipes: [],
providers: [LoginService, SearchService, TasksService],
directives: [RouterActive],
encapsulation: ViewEncapsulation.None,
styles: [
require('!raw!normalize.css'),
require('!raw!../assets/css/animate.css'),
require('./app.component.scss')
],
template: require('./app.component.html')
})
export class App {
constructor(private translate: TranslateService,
public appState: AppState) {
Resource.map(ENDPOINTS.API.toString(), 'http://localhost:3002/api');
let userLang = navigator.language.split('-')[0]; // use navigator lang if available
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'pl';
translate.setDefaultLang('en');
translate.use('pl');
}
ngOnInit() {
}
}
提供商不适用于路由器......现在......在rc4
中login服务:
@Injectable()
export class LoginService {
private user: User = <User>{
avatar_url: '/assets/img/avatars/u6.png'
};
constructor(private rest: Resource<ENDPOINTS, User, User[]>) {
this.rest.add(ENDPOINTS.API, 'users');
}
答案 0 :(得分:0)
您需要在TranslateService
或AppState
bootstrap(...)
和@Component(..., providers: [...]