当前位置: 首页 > 面试题库 >

找不到模块“ angular2 / angular2”

水恩
2023-03-14
问题内容

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

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文件是:

import {bootstrap} from 'angular2/angular2';

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

bootstrap(login);

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

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:

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "sourceMap": true,
        "watch": true,
        "removeComments": true,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true
    }
}

我已经使用以下命令安装了angular2的类型:

tsd install angular2 --save

请帮助纠正错误。


问题答案:

@simon错误说的是输入错误。但是对于其他进口商品,我已经发布了此答案,可能对其他人也有用。

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中,因此无需导入

import {view} from 'angular2/core'

更新2

由于angular2在RC中,因此所有导入都发生了重大变化,如果所有更新的导入都在这里,则为列表-

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


 类似资料:
  • 我试图找到此错误的任何解决方案,但没有任何对我有用。我有一个简单的Angular2应用程序,使用Angulal-CLI创建。当我在浏览器中提供此应用程序时,我收到此错误:我正在尝试在加载中使用不同的路径儿童: 文件夹 应用程序模块 app-routing.module.ts test.module.ts 堆栈跟踪

  • 问题内容: Mac OSX El capitan | angular-cli:0.1.0 | 节点:5.4.0 | 操作系统:darwin x64 我尝试根据angular-cli Wiki安装第三方npm模块:https : //github.com/angular/angular-cli/wiki/3rd-party- libs 但失败。我已经为此苦苦挣扎了好几天了,非常感谢您的帮助。 得到错

  • 我对Angular2是新手。我正在学习。这是第一个简单的教程,叫做猜数字 我使用了github提供的示例https://github.com/chandermani/angular2byexample/tree/master/guessthenumber中描述的代码。 它在浏览器中加载得很好。我有问题的是IntelliJ设置。 IntelliJ返回以下错误。如截图所示。找不到模块“@Angular

  • 问题内容: 我最近在计算机上安装了cx_Oracle模块,以连接到远程Oracle数据库服务器。(我身边没有Oracle客户端)。 Python:2.7 x86版 Oracle:版本11.1.X x64 Cx_Oracle:版本5.1.2-11g.win32-py2.7 然后,每次我运行脚本时,脚本都会失败并显示以下消息: ImportError:DLL加载失败:找不到指定的模块。 我想知道是否我