首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到模块‘angular2 2/angular2’

找不到模块‘angular2 2/angular2’
EN

Stack Overflow用户
提问于 2016-01-09 18:43:08
回答 11查看 12.9K关注 0票数 23

我正在用angular2和gulp开发一个节点应用程序。我编写了一个组件文件login.ts如下:

代码语言:javascript
复制
import {Component, View} from 'angular2/angular2';
import {FormBuilder,  formDirectives } from 'angular2/forms';
@Component({
  selector: 'login',
  injectables: [FormBuilder]
})
@View({
  templateUrl: '/scripts/src/components/login/login.html',
  directives: [formDirectives]
})

export class login {

}

我的bootstrap.ts文件是:

代码语言:javascript
复制
import {bootstrap} from 'angular2/angular2';

import {login} from './components/login/login';

bootstrap(login);

但是,当我编译这些文件时,它会给出以下错误:

代码语言:javascript
复制
client\bootstrap.ts(1,25): error TS2307: Cannot find module 'angular2/angular2'.
client\components\login\login.ts(1,31): error TS2307: Cannot find module 'angular2/angular2
client\components\login\login.ts(2,45): error TS2307: Cannot find module 'angular2/forms'.

这是我的tsconfig.json:

代码语言:javascript
复制
{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "sourceMap": true,
        "watch": true,
        "removeComments": true,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true
    }
}

我已经使用以下方法安装了用于angular2的输入:

代码语言:javascript
复制
tsd install angular2 --save

请帮助修复错误。

EN

回答 11

Stack Overflow用户

回答已采纳

发布于 2016-01-09 19:13:23

正如“simon in imports”中所说的那样。但是对于进一步的进口,我贴出了这个答案,也许这对其他人也是有用的。

代码语言:javascript
复制
import {Component, View, Directive, Input, Output, Inject, Injectable, provide} from 'angular2/core'; 

import {bootstrap} from 'angular2/platform/browser';

import {CORE_DIRECTIVES, FORM_DIRECTIVES, NgClass, NgIf  NgForm, Control, ControlGroup, FormBuilder, Validators} from 'angular2/common';

import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Router, LocationStrategy, HashLocationStrategy} from 'angular2/router';

import {Http, HTTP_PROVIDERS, RequestOptions, Headers, Request, RequestMethod} from 'angular2/http'

更新-

@View现在不再在angular2中了,所以不需要导入

代码语言:javascript
复制
import {view} from 'angular2/core'

更新2

由于angular2在RC中,所以所有的导入都发生了急剧变化,这里是列表,如果所有更新的导入-

代码语言:javascript
复制
angular2/core -> @angular/core
angular2/compiler -> @angular/compiler
angular2/common -> @angular/common
angular2/platform/common -> @angular/common
angular2/common_dom -> @angular/common
angular2/platform/browser -> @angular/platform-browser-dynamic
angular2/platform/server -> @angular/platform-server
angular2/testing -> @angular/core/testing
angular2/upgrade -> @angular/upgrade
angular2/http -> @angular/http
angular2/router -> @angular/router
angular2/platform/testing/browser -> @angular/platform-browser-dynamic/testing
票数 34
EN

Stack Overflow用户

发布于 2016-01-09 18:45:22

在进行beta之前,它将模块更改为

代码语言:javascript
复制
import {Component, View} from 'angular2/core';

还将引导程序更改为

代码语言:javascript
复制
import {bootstrap} from 'angular2/platform/browser';

因此,网上的许多博客文章都过时了:

票数 24
EN

Stack Overflow用户

发布于 2016-05-25 10:52:31

根据Angular2 rc1的新版本,您可以将package.json更新为

代码语言:javascript
复制
"dependencies": {
    "@angular/common": "2.0.0-rc.1",
    "@angular/compiler": "2.0.0-rc.1",
    "@angular/core": "2.0.0-rc.1",
    "@angular/http": "2.0.0-rc.1",
    "@angular/platform-browser": "2.0.0-rc.1",
    "@angular/platform-browser-dynamic": "2.0.0-rc.1",
    "@angular/router": "2.0.0-rc.1",
    "@angular/router-deprecated": "2.0.0-rc.1",
    "@angular/upgrade": "2.0.0-rc.1",
    .....
 }

此外,还在组件或容器中导入如下内容:

代码语言:javascript
复制
import { Component } from '@angular/core';
import {ROUTER_DIRECTIVES, Router, RouteParams} from '@angular/router-deprecated';
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34697466

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档