2017-10-13 8 views
0

각도 2 애플리케이션 개발을 시작하려고합니다. YouTube에 비디오를 발견하고 함께 실행했습니다. Chrome에서만 좋은 결과를 얻었습니다. IE 11에서 동일한 응용 프로그램을 실행할 때 다음 오류가 발생합니다.Angular 2 애플리케이션은 Chrome에서 실행되지만 IE는 실행되지 않습니다.

Error: (SystemJS) Syntax error 
SyntaxError: Syntax error 
at Anonymous function (eval code:4:1) 
at Anonymous function (eval code:1:31) 
Evaluating http://localhost:52688/app/app.module.js 
Evaluating http://localhost:52688/app/main.js 
Error loading http://localhost:52688/app/main.js 

그래서 해결책을 찾기 위해 google로 이동합니다. 나는 IE 11이 es6을 지원하지 않는다는 것을 알았으므로 tsconfig.json에서 내 대상 프레임 워크를 es6에서 es5로 변경해야합니다. 분명히 내 응용 프로그램은 이것에 대해 행복하지 않았고 모든 종류의 오류를 줄을 따라 반환합니다.

"Build:Cannot find name 'Map'" and "Build:Cannot find name 'Set'". 

다시, Google을 사용하지 마십시오. 나는이 두 객체가 이제 es5와 es6 사이에서 완전히 다른 것을 배웠고 많은 사람들이 약간의 심을 제안했다. 따라서 shim을 패키지에 추가합니다 .json, 패키지를 복원하고 내 메인 페이지에서 참조하십시오. 나는 다시 건축을 시도하고 성공하지 못합니다.

나는이 심들이 실제로 작동하는지에 관해 질문을하지만 나는 그것들을 어떻게 작동시키는지를 잘 모르고있다. 당신의 도움을 주셔서 감사합니다. 여기에 관련된 모든 코드가 있습니다. 더 필요한 것이 있으면 알려주세요.

package.json

{"name": "angular2withvs2015", 
"version": "1.0.0", 
"dependencies": { 
"@angular/common": "~2.1.1", 
"@angular/compiler": "~2.1.1", 
"@angular/core": "~2.1.1", 
"@angular/forms": "~2.1.1", 
"@angular/http": "~2.1.1", 
"@angular/platform-browser": "~2.1.1", 
"@angular/platform-browser-dynamic": "~2.1.1", 
"@angular/router": "~3.1.1", 
"@angular/upgrade": "~2.1.1", 
"bootstrap": "3.3.7", 
"core-js": "^2.4.1", 
"reflect-metadata": "^0.1.8", 
"rxjs": "5.4.3", 
"systemjs": "0.19.39", 
"zone.js": "^0.6.25", 
"es6-shim": "0.35.3"}, 
"devDependencies": { 
"@types/core-js": "^0.9.41", 
"@types/node": "6.0.40", 
"gulp": "3.9.1", 
"gulp-tsc": "^1.2.5", 
"gulp-typescript": "^3.1.2", 
"rimraf": "^2.5.4", 
"typescript": "^2.0.7"}} 

tsconfig.json

{ 
    "compilerOptions": { 
    "target": "es6", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": true, 
    "types": [] 
    }, 
    "exclude": [ 
    "node_modules" 
    ] 
} 

app.component.ts

import { Component,OnInit } from '@angular/core'; 
@Component({ 
    selector: 'my-app', 
    template: `<h1>Hello {{name}}</h1>`, 
    providers:[GetDataService] 
}) 
export class AppComponent { 
    name = 'Angular 2 (From component)'; 
} 

system.config.js

(function (global) { 
var map = { 
    'app': '/app', 
    '@angular': '/node_modules/@angular', 
    'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api', 
    'rxjs': '/node_modules/rxjs' 

}, 
    packages = { 
     'app': { main: './main.js', defaultExtension: 'js' }, 
     'angular2-in-memory-web-api': { main: './index.js', defaultExtension: 'js' }, 
     'rxjs': { defaultExtension: 'js' } 
    }, 
    ngPackageNames = [ 
     'common', 
     'compiler', 
     'core', 
     'http', 
     'platform-browser', 
     'platform-browser-dynamic', 
     'router', 
     'forms' 
    ]; 

function packUmd(pkgName) { packages['@angular/' + pkgName] = { main: '/bundles/' + pkgName + '.umd.min.js', defaultExtension: 'js' } } 

ngPackageNames.forEach(packUmd); 


var config = { 
    map: map, 
    packages: packages 
}; 

System.config(config);})(this); 
,536,913 또한, 당신의 index.html을에 이러한 참조를 모두 추가해야합니다

{"compilerOptions": { 
"lib": [ "es5", "dom", "es6", "dom.iterable", "scripthost" ], 
"noLib": false, 
"target": "es5", 
"module": "commonjs", 
"moduleResolution": "node", 
"sourceMap": true, 
"emitDecoratorMetadata": true, 
"experimentalDecorators": true, 
"removeComments": false, 
"noImplicitAny": true, 
"types": ["node"]}, 
"exclude": [ 
"node_modules" 
] 

: 63,210

을 Default.aspx는

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Angular2Demo10.Default" %> 
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server">  
<script src="node_modules/es6-shim/es6-shim.js"></script> 
<script src="node_modules/core-js/client/shim.js"></script> 

<script src="node_modules/zone.js/dist/zone.js"></script> 
<script src="node_modules/systemjs/dist/system.src.js"></script> 
<script src="system.config.js"></script> 
<script> 
    System.import('app').then(null, console.error.bind(console)); 
</script> 
</head> 
<body> 
    <h1>Hello World (Default.aspx)</h1> 
    <my-app>Loading...</my-app> 
</body></html> 
+0

https://stackoverflow.com/questions/33332394/angular-2-typescript-cant-find-names –

+0

I 이것이 무엇을 의미하는지 모른다. 당신은 그것을 단순화 할 수 있습니까? 나는 내 꾸러미에서 물건을 바꿀 필요가 있다고 생각하고있다 .Json하지만 나는 무엇을 확신하지 못한다. – champ8686

+0

많은 솔루션이 있습니다. 그냥 시간을 보내고 그 중 몇 가지를 시도해 보라. 메인 파일에'/// <참조 경로 = "node_modules/angular2/typings/browser.d.ts"/>'를 추가하거나' @ types/es6-shim'을'package.json'에 넣습니다. –

답변