2016-01-09 54 views
22

Sto sviluppando un'applicazione nodo con angular2 e gulp. Ho scritto un componente login.ts file come segue:Impossibile trovare il modulo 'angular2/angular2'

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 { 

} 

E il mio file bootstrap.ts è:

import {bootstrap} from 'angular2/angular2'; 

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

bootstrap(login); 

ma quando compilo questi file mi dà i seguenti errori:

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'. 

Ecco il mio tsconfig.json:

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

Ho installato il tipizzazione per angular2 utilizzando:

tsd install angular2 --save 

prega di aiutare a correggere l'errore.

+1

@View è stata abbandonata in modo da questo codice non è più valido in Angular2 – Satch3000

+1

Penso che sia importante menzionare ...Esiste una differenza tra l'importazione da "angular2" vs "@angular". Se stai usando cdn (ad esempio, '

24

ha cambiato modulo appena prima di andare beta

import {Component, View} from 'angular2/core'; 

FYI: bootstrap anche cambiato

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

come risultato un sacco di post del blog sulla rete non sono aggiornati: - (

+0

TS2300: identificatore duplicato '....'. ottenere questo errore se ho apportato sopra le modifiche – Rhushikesh

+0

se faccio così /node_modules/angular2/typings/node/node.d.ts ottenere in conflitto con typings \ node \ node.d.ts – Rhushikesh

+0

typings \ node \ node.d.ts è bisogno di express, mangusta – Rhushikesh

0

importazione da '' angular2/angular2' era nella versione precedente che non è più supportata ora .Così Ora dobbiamo importare lo stesso da 'angular2/core'.For dettaglio riferimento uso (https://angular.io/guide/quickstart)

+0

sì, quickstart è il modo migliore per rimanere aggiornati con le modifiche in Angular2 – kimbaudi

4

Come per la nuova release di Angular2 RC1, è possibile aggiornare il package.json a

"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", 
    ..... 
} 

in aggiunta a questo importare anche come segue nel componente o contenitore:

import { Component } from '@angular/core'; 
import {ROUTER_DIRECTIVES, Router, RouteParams} from '@angular/router-deprecated'; 
3

si prega di notare che, come forma Angular2 rilascio finale la risposta corretta è questa.

import {Component, View, Directive, Input, Output, Inject, Injectable, provide} from 'angular/core'; 

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

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

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

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

Questo è vero, come ha detto in aggiornamento yups 2 dall'alto

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 
3

è necessario aggiornare la versione Angular2 nella versione finale -

E poi usare come ----

import { Component } from '@angular/core'; 

c'è una libreria aggiornata come --- '@angular/core'

-1
  • Prima aggiornare le librerie angular2 su packege.json.
  • Seconda

    import {Component} from "@angular/core"; 
    import {FormBuilder } from "@angular/forms"; 
    
    @Component({ 
        selector: "login", 
        providers: [FormBuilder], 
        templateUrl: "/scripts/src/components/login/login.html" 
    }) 
    
    
    export class login { 
    
    } 
    
0

'angular2/angular2' non è una valida dipendenze di angular2

bisogna prima controllo del file package.json "@ angolare/core" esistono o non

"dependencies": { 
    "@angular/common": "2.0.0", 
    "@angular/compiler": "2.0.0", 
    "@angular/core": "2.0.0", 
    "@angular/http": "2.0.0", 
    "@angular/platform-browser": "2.0.0", 
    "@angular/platform-browser-dynamic": "2.0.0", 
    "@angular/router": "2.0.0", 
    "@angular/router-deprecated": "2.0.0", 
    "@angular/upgrade": "2.0.0", 
    ..... 
} 

vedere il file del componente come questo e anche che hai anche usare formGroup come belove

import { Component, OnInit, DoCheck } from '@angular/core' 
    import { Router } from '@angular/router' 

    import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms' 

    @Component({ 
     selector: 'app-user-profile', 
     templateUrl: './user-profile.component.html', 
     styleUrls: ['./user-profile.component.scss'], 
    }) 
    export class UserProfileComponent implements OnInit, DoCheck { 
     profileForm: FormGroup 

     constructor(private fb: FormBuilder) { 
     this.profileForm = this.fb.group({ 
      firstName: ['', Validators.required], 
      lastName: ['', Validators.required], 
      email: ['', Validators.required], 
      mobileNo: ['', Validators.required] 
     }); 
    } 

di quanto si deve importare ReactiveFormsModule in app.module.ts il file
importazione {} ReactiveFormsModule da '@ angolari/forme';

senza ReactiveFormsModule formGroup non funziona ne fanno l'errore

import { NgModule } from '@angular/core'; 
import { CommonModule } from '@angular/common'; 
import { UserProfileComponent } from './user-profile.component'; 

import { UserProfileRoutingModule } from './user-profile-routing.module'; 
import { ReactiveFormsModule } from '@angular/forms'; 

@NgModule({ 
    imports: [ 
    CommonModule, 
    UserProfileRoutingModule, 
    ReactiveFormsModule 
    ], 
    declarations: [UserProfileComponent] 
}) 
0

Il modo migliore per dare di angular2 progetto sta usando angolare CLI.

La CLI Angolare semplifica la creazione di un'applicazione che funziona già, immediatamente. Segue già le nostre migliori pratiche!

per favore check this per ulteriori dettagli.

3

Si sta tentando di accedere a Component dalla directory errata/vecchia di node_modules. prega di accedere a componente dal

import { Component, OnInit } from '@angular/core'; 

invece di: import { Component, View } from 'angular2/angular2';

E

accesso bootstrap dal percorso sotto:

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