使用Angular2中的globalDependencies(Typescript tsd文件)

使用Angular2中的globalDependencies(Typescript tsd文件),typescript,angular,Typescript,Angular,我试图在Angular2项目(RC.0)中使用DefiniteTypelyTyped中的typescript tsd,但全局依赖项似乎无法正确加载: typings install --save dt~hellojs --global --save npm install --save hellojs 我有这样的配置: typings.json: "globalDependencies": { "hellojs": "registry:dt/hellojs#0.2.3+2016042314

我试图在Angular2项目(RC.0)中使用DefiniteTypelyTyped中的typescript tsd,但全局依赖项似乎无法正确加载:

typings install --save dt~hellojs --global --save
npm install --save hellojs
我有这样的配置:

typings.json:

"globalDependencies": {
  "hellojs": "registry:dt/hellojs#0.2.3+20160423145325"
}
angular.cli.build.js:

module.exports = function(defaults) {
  return new Angular2App(defaults, {
    vendorNpmFiles: [
      'systemjs/dist/system-polyfills.js',
      'systemjs/dist/system.src.js',
      'zone.js/dist/**/*.+(js|js.map)',
      'es6-shim/es6-shim.js',
      'reflect-metadata/**/*.+(js|js.map)',
      'rxjs/**/*.+(js|js.map)',
      '@angular/**/*.+(js|js.map)',
      'angular2-moment/**/*.+(js|js.map)',
      'moment/**/*.+(js|js.map)',
      'hellojs/**/*.+(js|js.map)'
    ]
  });
};
system-config.ts

/** Map relative paths to URLs. */
const map: any = {
  'moment': 'vendor/moment',
  'angular2-moment': 'vendor/angular2-moment',
  'hellojs': 'vendor/hellojs/dist'
};

/** User packages configuration. */
const packages: any = {
  'moment': { main: 'moment.js', defaultExtension: 'js' },
  'angular2-moment': { main: 'index.js', defaultExtension: 'js' },
  'hellojs': { main: 'hello.all.js' }
};
但是,如果我使用angular模块中的新依赖项,如下所示:

import {Component} from "@angular/core";
import {FormBuilder, ControlGroup} from "@angular/common";
import {ROUTER_DIRECTIVES, Router} from "@angular/router";
import {LoginResourceService} from "../shared/services/resources/login-resource.service";
import {AuthService} from "../shared/services/auth.service";
import {AppRoutes} from "../app-routes";

@Component({
  moduleId: module.id,
  selector: 'app-login',
  templateUrl: 'login.component.html',
  directives: [ROUTER_DIRECTIVES],
  providers: [LoginResourceService],
  styleUrls: ['login.component.css']
})
export class LoginComponent {

  userForm:ControlGroup;
  errorMessage:string;

  constructor(formBuilder:FormBuilder, private _loginResource:LoginResourceService, public router:Router,
              private _auth:AuthService) {
    this.userForm = this.buildLoginForm(formBuilder);
  }
  // ...
  example() {
    hello.init({});
  }

}
我收到编译器错误:

Error: Typescript found the following errors:
  /Users/fer2d2/dev/personal/web-projects/front-joinfinity/tmp/broccoli_type_script_compiler-input_base_path-xa8whw1k.tmp/0/src/app/+login/login.component.ts (62, 5): Cannot find name 'hello'.
如果我尝试从“hellojs”以hello的形式导入模块,则失败仍然存在

如何使用Angular2的全局依赖性

提前谢谢

编辑

与:
从“hellojs”导入{hello}
从“hellojs”导入hello
import hello=require(“hellojs”)

我得到了这个错误:

Error: Typescript found the following errors: /Users/fer2d2/dev/personal/web-projects/front-joinfinity/tmp/broccoli_type_scrip‌​t_compiler-input_base_path-tKuuBwei.tmp/0/src/app/+login/login.component.ts (7, 21): Cannot find module 'hellojs'.

似乎Typescript或systemjs没有正确加载globalDependencies tsd。

最后我解决了我的问题:

在Angular2中,使用Angular CLI和Angular CLI,有一个名为typings.d.ts的文件,该文件导入通过
typings install安装的所有打字。在此文件中,您可以看到以下导入行:

/// <reference path="../typings/browser.d.ts" />
我的问题似乎与打字的最新更新有关,其中“ambient”被替换为“global”作为此依赖项的前缀


尝试:
从“hellojs”导入{hello}
和:
从“hellojs”导入hello
导入hello=require(“hellojs”)
的错误是什么。使用:
import{hello}from“hellojs”
import hello from“hellojs”
import hello=require(“hellojs”)
我发现了这个错误:
错误:Typescript发现了以下错误:/Users/fer2d2/dev/personal/web projects/front joinfinity/tmp/brocoli\u type\u script\u compiler-input\u base\u path-tKuuBwei.tmp/0/src/app/+login/login.component.ts(7,21):找不到模块“hellojs”。
/// <reference path="../typings/browser.d.ts" />