javascript - (SystemJS) 意外标记 < ( ASP.net + Angular 4)

标签 javascript asp.net angular

不确定如何解决此问题;我正在尝试使用 ngx-translate 动态加载我的本地化值。 这是一个带有 Angular 4 的 asp.net。 这是我的 System.config.js

(function (global) {
System.config({
    paths: {
        // paths serve as alias
        'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
        // our app is within the app folder
        app: '/app',

        // angular bundles
        '@ngx-translate/core': 'npm:@ngx-translate/core/bundles/core.umd.js',
        '@ngx-translate/http-loader': 'npm:@ngx-translate/http-loader/bundles/http-loader.umd.js',
        '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
        '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
        '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
        '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
        '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
        '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
        '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
        '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
        // other libraries
        'rxjs': 'npm:rxjs',
        'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
        
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
        app: {
            main: 'main.js', defaultExtension: 'js',
                meta: {
      './*.js': {
            loader: 'systemjs-angular-loader.js'
        }
    }
        },
        rxjs: {
            defaultExtension: 'js'
        }
       
    }
});
})(this);

这是我的应用程序模块:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms'

 import { AppComponent } from './app.component';

import { TranslateModule, TranslateLoader } from "@ngx-translate/core";
import { TranslateHttpLoader } from "@ngx-translate/http-loader";
import { HttpClient, HttpClientModule } from "@angular/common/http";

// AoT requires an exported function for factories
export function HttpLoaderFactory(httpClient: HttpClient) {
    return new TranslateHttpLoader(httpClient, "i18n/", ".json");
}

@NgModule({
declarations: [
     AppComponent
],
imports: [
  BrowserModule, FormsModule, AppRoutingModule, TranslateModule.forRoot({
      loader: {
          provide: TranslateLoader,
          useFactory: HttpLoaderFactory,
          deps: [HttpClient]
      }
  })
  ],
  providers: [],
 bootstrap: [AppComponent]
})
 export class AppModule { }

这是我试图遵循的示例。 https://plnkr.co/edit/WccVZSBM0rUgq2sXSUbe?p=preview

这是我遇到的错误

Error: (SystemJS) Unexpected token <
    SyntaxError: Unexpected token <
        at eval (<anonymous>)
        at Object.eval (http://localhost:63021/app/app.module.js:25:14)
        at eval (http://localhost:63021/app/app.module.js:69:4)
        at eval (http://localhost:63021/app/app.module.js:70:3)
    Evaluating http://localhost:63021/@ngx-translate/core
    Evaluating http://localhost:63021/app/app.module.js
    Evaluating http://localhost:63021/app/main.js
    Error loading http://localhost:63021/app/main.js
        at eval (<anonymous>)
        at Object.eval (http://localhost:63021/app/app.module.js:25:14)
        at eval (http://localhost:63021/app/app.module.js:69:4)
        at eval (http://localhost:63021/app/app.module.js:70:3)
    Evaluating http://localhost:63021/@ngx-translate/core
    Evaluating http://localhost:63021/app/app.module.js
    Evaluating http://localhost:63021/app/main.js
    Error loading http://localhost:63021/app/main.js

我的Main.ts

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app.module';


platformBrowserDynamic().bootstrapModule(AppModule);

我的项目结构 Project Structure

最佳答案

http 和 HttpClient 是两个不同的模块(在 Angular 4.3.4 下)

添加到systemjs.config.js:

map: {
       ;
        '@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js',
        'tslib': 'npm:tslib/tslib.js',

添加到您的app.module.ts:

@NgModule({
     declarations: [AppComponent],
     imports: [BrowserModule, FormsModule,HttpClientModule, AppRoutingModule, TranslateModule.forRoot({

参见here了解更多详情

关于javascript - (SystemJS) 意外标记 < ( ASP.net + Angular 4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46372269/

相关文章:

html - 导航栏中的下拉列表不显示元素列表(Angular 6)

javascript - 根据屏幕宽度隐藏/显示 Div

c# - ASP.NET 中的缓存控制 header

asp.net - 在 ASP.NET 中诊断 "Thread was being aborted."

c# - Properties.Settings 在 ASP.NET Core 中不可用

javascript - Firebase Angular 7 身份验证持久性

javascript - Meteor Random 包 vs randomSeed

javascript - Jquery UI 多个日期选择器选择

javascript - 阻止 PDF 文件在拖放时打开

java - Nativescript + Angular - 无法实例化接收器....未找到类