gpt4 book ai didi

node.js - 找不到模块 'angular2/angular2'

转载 作者:IT老高 更新时间:2023-10-28 22:04:01 26 4
gpt4 key购买 nike

我正在使用 angular2 和 gulp 开发一个 Node 应用程序。我写了一个组件文件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 所说的 yups 错误在导入中。但是对于进一步的进口,我已经发布了这个答案,这可能对其他人也有用。

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

关于node.js - 找不到模块 'angular2/angular2',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34697466/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com