Angular 找不到模块'@角度/平台/浏览器';
我已经使用Angular 找不到模块'@角度/平台/浏览器';,angular,angular2-routing,Angular,Angular2 Routing,我已经使用ng new myproject创建了我的angular2应用程序,现在我要引导我的应用程序。下面是我的boot.ts文件: import {bootstrap} from '@angular/platform/browser'; import {AppComponent} from './app.component' import {ROUTER_PROVIDERS} from '@angular/router' bootstrap(AppComponent,[ROUTER_
ng new myproject
创建了我的angular2
应用程序,现在我要引导我的应用程序。下面是我的boot.ts
文件:
import {bootstrap} from '@angular/platform/browser';
import {AppComponent} from './app.component'
import {ROUTER_PROVIDERS} from '@angular/router'
bootstrap(AppComponent,[ROUTER_PROVIDERS] );
此文件中有两个问题:
在第一行“@angular/platform/browser”
中,它抱怨
Cannot find module '@angular/platform/browser'.
在第三行从'@angular/ROUTER'
导入{ROUTER\u PROVIDERS}中,它抱怨:
Module '"c:/Users/Salman/Desktop/Courses/Internship/Angular2/Qminder/Qminder/node_modules/@angular/router/index"' has no exported member 'ROUTER_PROVIDERS'.
那么我该如何修复它们呢?
命令
ng new
是否有任何错误?从Angular Release候选版本4开始,您应该从以下模块导入引导功能:
import { bootstrap } from '@angular/platform-browser-dynamic';
路由器模块在angular的最新版本中已更改,因此您需要创建“app.routes.ts”文件,该文件将包含以下内容:
import { provideRouter, RouterConfig } from '@angular/router';
const routes: RouterConfig = [
{ path: 'home', component: HomeComponent },
{ path: '**', component: PageNotFoundComponent }
];
export const appRouterProviders = [
provideRouter(routes)
];
然后需要导入“appRouterProviders”并将其提供给“bootstrap”方法:
有关最新路由器的更多信息,请访问:
import { bootstrap } from '@angular/platform-browser-dynamic';
import { AppComponent } from './app.component';
import { appRouterProviders } from './app.routes';
bootstrap(AppComponent, [
appRouterProviders
])
.catch(err => console.error(err));