设置AngularJS使用`jspm` 2项目 [英] Setup AngularJS 2 Project using `jspm`

查看:198
本文介绍了设置AngularJS使用`jspm` 2项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安装AngularJS 2使用项目 JSPM ,首先我已经通过在angular.io下面的指令试图设置,它的工作就好了。

所以我想设置另一个相同的项目,但使用​​ JSPM 我有关于错误区规格要求,我试过谷歌,但我没有发现任何迄今为止,所以请指导我该怎么办

angular.io版本

应用程序/ index.ts

 从'angular2 /平台/浏览器的进口{}引导;
进口{} AppComponent从'./components/App';引导(AppComponent);

index.html的

 <!DOCTYPE HTML>
< HTML LANG =ENGT&;
< HEAD>
    <间的charset =UTF-8>
    <标题> AngularJS 2'; /标题>
    <脚本SRC =HTTPS://$c$c.angularjs.org/2.0.0-beta.11/angular2-polyfills.js>< / SCRIPT>
    <脚本SRC =HTTPS://$c$c.angularjs.org/tool​​s/system.js>< / SCRIPT>
    &所述; SCRIPT SRC =htt​​ps://npmcdn.com/typescript@1.8.9/lib/typescript.js>&下; /脚本>
    <脚本SRC =HTTPS://$c$c.angularjs.org/2.0.0-beta.11/Rx.js>< / SCRIPT>
    <脚本SRC =HTTPS://$c$c.angularjs.org/2.0.0-beta.11/angular2.js>< / SCRIPT>    <脚本类型=文/ JavaScript的>
        System.config({
            transpiler:打字稿,
            typescriptOptions:{emitDecoratorMetadata:真正},
            包:{应用:{defaultExtension:'TS'​​}}
        });        System.import(应用程序/指数');
    < / SCRIPT>
< /头>
<身体GT;
    &所述; H3> AngularJS 2'; / H3>
    <小时>
    <试验应用>加载...< /测试应用程序与GT;
< /身体GT;
< / HTML>

JSPM 版本

终端

  JSPM安装angular2反映,metada zone.js

应用程序/ index.ts

 进口'zone.js';
进口反映的元数据';从angular2 /平台/浏览器的进口{}引导;
进口{} AppComponent从'./components/App';引导(AppComponent);

index.html的

 <!DOCTYPE HTML>
< HTML LANG =ENGT&;
< HEAD>
    <间的charset =UTF-8>
    <标题> AngularJS 2'; /标题>    <脚本类型=文/ JavaScript的SRC =jspm_packages / system.js>< / SCRIPT>
    <脚本类型=文/ JavaScript的SRC =config.js>< / SCRIPT>    <脚本类型=文/ JavaScript的>
        System.config({
            transpiler:打字稿,
            typescriptOptions:{emitDecoratorMetadata:真正},
            包:{应用:{defaultExtension:'TS'​​}}
        });        System.import(应用程序/指数');
    < / SCRIPT>
< /头>
<身体GT;
    &所述; H3> AngularJS 2'; / H3>
    <小时>
    <试验应用>加载...< /测试应用程序与GT;
< /身体GT;
< / HTML>


解决方案

请参见 https://开头的github .COM /角/角/问题/ 7660

下面的技巧固定对我来说: https://github.com/角/角/问题/ 7660#issuecomment-198624392

在主类中添加这个(略低于进口'zone.js';

进口'zone.js /距离/长堆栈跟踪区';

I'm trying to setup AngularJS 2 project using jspm, firstly I had tried to setup by following instruction on the angular.io, it's working just fine

So I'm trying to setup another same project but using jspm I'm having error about "ZoneSpec required", I had tried to google but I have found nothing so far, so please guide me what to do

angular.io Version

app/index.ts

import { bootstrap }    from 'angular2/platform/browser';
import { AppComponent } from './components/App';

bootstrap(AppComponent);

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AngularJS 2</title>
    <script src="https://code.angularjs.org/2.0.0-beta.11/angular2-polyfills.js"></script>
    <script src="https://code.angularjs.org/tools/system.js"></script>
    <script src="https://npmcdn.com/typescript@1.8.9/lib/typescript.js"></script>
    <script src="https://code.angularjs.org/2.0.0-beta.11/Rx.js"></script>
    <script src="https://code.angularjs.org/2.0.0-beta.11/angular2.js"></script>

    <script type="text/javascript">
        System.config({
            transpiler: 'typescript',
            typescriptOptions: { emitDecoratorMetadata: true },
            packages: { 'app': { defaultExtension: 'ts' } }
        });

        System.import('app/index');
    </script>
</head>
<body>
    <h3>AngularJS 2</h3>
    <hr>
    <test-app>Loading ...</test-app>
</body>
</html>

jspm Version

Terminal

jspm install angular2 reflect-metada zone.js

app/index.ts

import 'zone.js';
import 'reflect-metadata';

import { bootstrap }    from 'angular2/platform/browser';
import { AppComponent } from './components/App';

bootstrap(AppComponent);

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AngularJS 2</title>

    <script type="text/javascript" src="jspm_packages/system.js"></script>
    <script type="text/javascript" src="config.js"></script>

    <script type="text/javascript">
        System.config({
            transpiler: 'typescript',
            typescriptOptions: { emitDecoratorMetadata: true },
            packages: { 'app': { defaultExtension: 'ts' } }
        });

        System.import('app/index');
    </script>
</head>
<body>
    <h3>AngularJS 2</h3>
    <hr>
    <test-app>Loading ...</test-app>
</body>
</html>

解决方案

See https://github.com/angular/angular/issues/7660

The following tip fixed it for me: https://github.com/angular/angular/issues/7660#issuecomment-198624392

Add this in your main class (just under import 'zone.js';) :

import 'zone.js/dist/long-stack-trace-zone';

这篇关于设置AngularJS使用`jspm` 2项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆