Cannot find module 'angular2/angular2'

后端 未结 11 855
有刺的猬
有刺的猬 2020-11-30 06:43

I am developing an node app with angular2 and gulp. I have written a component file login.ts as follows:

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


        
相关标签:
11条回答
  • 2020-11-30 07:04

    you have to Update Angular2 version in final version --

    And then use like ----

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

    there is a updated library like --- '@angular/core'

    0 讨论(0)
  • 2020-11-30 07:06

    Please note that as form Angular2 final release the correct answer is this.

    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'
    

    This is true as said in yups update 2 from above

    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
    
    0 讨论(0)
  • You are trying to access Component from wrong/old directory of node_modules. Please access Component from

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

    instead of : import { Component, View } from 'angular2/angular2';

    AND

    Access bootstrap from bellow path :

    import { bootstrap } from 'angular2/platform/browser';
    
    0 讨论(0)
  • 2020-11-30 07:06
    import {Component} from "@angular/core";
    
    @Component({
      selector: "userForm",
      template: '<div><input type="text" name="name" [disabled]="flag"/></div>'
    });
    
    export class userForm{
     public flag = false; //boolean value: true/false
    }
    
    0 讨论(0)
  • 2020-11-30 07:07
    • First update your angular2 liberies at packege.json.
    • Second

       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 讨论(0)
  • 2020-11-30 07:14

    It changed module just ahead of going beta to

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

    FYI: bootstrap also changed to

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

    as a result a lot of the blog posts on the net are out of date :-(

    0 讨论(0)
提交回复
热议问题