直接用编译好的.js文件的话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
      '@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',
      '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
      // '@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.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: '../test.main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      }
    }
  });
})(this);

其中

main: '../test.main.js',
        defaultExtension: 'js'

里面必须写成js,如果忘了将.ts文件编译成.js文件的话,会报错,提示“GET http://127.0.0.1:8080/ (Not Found)”
如果是直接用.ts文件的话,system.config.js应该是这样的

(function (global) {
  System.config({
    // DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
    transpiler: 'ts',
    typescriptOptions: {
      // Copy of compiler options in standard tsconfig.json
      "target": "es5",
      "module": "commonjs",
      "moduleResolution": "node",
      "sourceMap": true,
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "noImplicitAny": true,
      "suppressImplicitAnyIndexErrors": true
    },
    meta: {
      'typescript': {
        "exports": "ts"
      }
    },


    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
      '@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',
      '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
      // '@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.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',
      'ts':                        'npm:plugin-typescript/lib/plugin.js',
      'typescript':                'npm:typescript/lib/typescript.js',


    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: '../test.main.ts',
        defaultExtension: 'ts'
      },
      rxjs: {
        defaultExtension: 'js'
      }
    }
  });
})(this);

相比上面,不但更改了两处.js变成.ts,还增加了两个部分
新增第一部分代码

// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
    transpiler: 'ts',
    typescriptOptions: {
      // Copy of compiler options in standard tsconfig.json
      "target": "es5",
      "module": "commonjs",
      "moduleResolution": "node",
      "sourceMap": true,
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "noImplicitAny": true,
      "suppressImplicitAnyIndexErrors": true
    },
    meta: {
      'typescript': {
        "exports": "ts"
      }
    },

新增第二部分代码

      'ts':                        'npm:plugin-typescript/lib/plugin.js',
      'typescript':                'npm:typescript/lib/typescript.js',

如果只增加第二部分代码,不增加第一部分代码,报错仍然是“GET http://127.0.0.1:8080/ (Not Found)”,如果只增加第一部分代码,不增加第二部分代码,报错会是“GET http://127.0.0.1:8080/ts (Not Found)”或者“GET http://127.0.0.1:8080/typesript (Not Found)”之类的。
搜狗截图20170126212205
平时测试代码,懒得每次编译ts就直接用这种模式。

随机文章

QQ漂流瓶更好玩了,装有GPS导航
QQ漂流瓶更好玩了,装有GPS导航

Java基础第六讲:流程控制(二)
Java基础第六讲:流程控制(二)

想找外国老公吗
想找外国老公吗

AngularJs的provider里面的装饰器decorator
AngularJs的provider里面的装饰器decorator

QQ电脑管家的Q盘登陆超时
QQ电脑管家的Q盘登陆超时

相关文章

angular表单验证$parsers和$validators方式区别
angular表单验证$parsers和$validators方式区别

苹果的chromebook
苹果的chromebook

Java基础第三讲:Java基本语法(二)
Java基础第三讲:Java基本语法(二)

Java基础第十二讲:面向对象基础(六)
Java基础第十二讲:面向对象基础(六)

再次分享下微信、易信自定义菜单。
再次分享下微信、易信自定义菜单。

工行,你真的不管firefox了吗
工行,你真的不管firefox了吗

内容分享:道招
本文链接:angularjs2会报错“GET http://127.0.0.1/traceur 404 (Not Found)”
道招声明:除特别标注或作者不详外,本站所有文章均为原创,转载请注明。欢迎共同关注互联网!