gpt4 book ai didi

未加载 Angular2 路由器弃用的依赖项

转载 作者:太空狗 更新时间:2023-10-29 17:23:44 25 4
gpt4 key购买 nike

我最近更新了我的 angular2 版本并遇到了以下问题:

  1. 路由器库不再存在,它已被 router-deprecated 取代。

  2. 我有这个菜单组件:

    import { Component }       from '@angular/core';
    import { DashboardComponent } from './dashboard.component'
    import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated';

    @Component({
    selector: 'main-menu',
    templateUrl: 'app/views/menu.html',
    directives: [ROUTER_DIRECTIVES],
    providers: [
    ROUTER_PROVIDERS
    ]
    })

    @RouteConfig([
    {
    path: '/dashboard',
    name: 'Dashboard',
    component: DashboardComponent,
    useAsDefault: true
    }
    ])

    export class MenuComponent {}
  3. 当我尝试加载该应用程序时,该应用程序失败了,因为它无法解析路由器弃用所需的文件。我收到以下错误:

Image of error

最佳答案

在 Angular2 RC.0 中你可能需要添加

'@angular/router-deprecated': {
main: 'index.js',
defaultExtension: 'js'
},

config.js 中的 packages

或者如果你想使用新路由器的话:

'@angular/router': {
main: 'index.js',
defaultExtension: 'js'
},

示例 config.js 来自 rc.0 Plunker

(function(global) {

var ngVer = '@2.0.0-rc.0'; // lock in the angular package version; do not let it float to current!

//map tells the System loader where to look for things
var map = {
'app': 'src', // 'dist',
'rxjs': 'https://npmcdn.com/rxjs@5.0.0-beta.6',
'angular2-in-memory-web-api': 'https://npmcdn.com/angular2-in-memory-web-api' // get latest
};

//packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'app.ts', defaultExtension: 'ts' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { defaultExtension: 'js' },
};

var packageNames = [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router-deprecated',
'@angular/testing',
'@angular/upgrade',
];

// add map entries for angular packages in the form '@angular/common': 'https://npmcdn.com/@angular/common@0.0.0-3'
packageNames.forEach(function(pkgName) {
map[pkgName] = 'https://npmcdn.com/' + pkgName + ngVer;
});

// add package entries for angular packages in the form '@angular/common': { main: 'index.js', defaultExtension: 'js' }
packageNames.forEach(function(pkgName) {
packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});

var config = {
transpiler: 'typescript',
typescriptOptions: {
emitDecoratorMetadata: true
},
map: map,
packages: packages
}

// filterSystemConfig - index.html's chance to modify config before we register it.
if (global.filterSystemConfig) { global.filterSystemConfig(config); }

System.config(config);

})(this);

关于未加载 Angular2 路由器弃用的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37000243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com