11

I am little confused here in angular2. Many example show like

import { Component } from "@angular/core"

But actually in node_module there is angular2directory exists. So logically it should be

import { Component } from "angular2/core" 

What is the difference between this two ?

Nishchit
  • 18,284
  • 12
  • 54
  • 81
  • Angular apps are modular. They consist of many files each dedicated to a purpose. Angular itself is modular. It is a collection of library modules each made up of several, related features that we'll use to build our application. When we need something from a module, we import it. Here we import the Angular Component decorator function from @angular/core because we need it to define our component. app/app.component.ts (import) import { Component } from '@angular/core'; – mayur May 10 '16 at 11:42
  • 1
    @mayur, I think you may have misunderstood the question. The OP is not asking what or why the import functions are used, but they are asking about the use of the `"@"` symbol. The answer below from Gunter explains this. Check out the changelog in the link they posted. – redfox05 Oct 20 '16 at 16:23

1 Answers1

9

That's a change that was introduced with the update from beta.17 to rc.0

https://github.com/angular/angular/blob/master/CHANGELOG.md#200-rc0-2016-05-02

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Any idea why the switch? – Ryan Rahlf May 15 '16 at 19:36
  • 1
    @RyanRahlf AFAIK there are name restrictions for namespaces on NPM and the `@` is one of these. They also don't want different namespaces for different Angular versions, just one for everything Angular. – Günter Zöchbauer May 15 '16 at 19:37
  • what if you use a module below **beta.17** in a **r.c.** project? Which syntax do you use then? – garrettmac Sep 25 '16 at 02:36
  • What beta 17 module? I'm sure Angular2 modules won't work together if versions differ. Perhaps with some luck you can make something work if ther versions only differ a bit, but there were always so many changes that it's very unlikely. – Günter Zöchbauer Sep 25 '16 at 06:51
  • @GünterZöchbauer. If I import only one component like `import { Component } from '@angular/core'` instead of `import * from '@angular/core'`, will it affect on the effectiveness of the code, not at the first glance ? – Suren Srapyan Feb 28 '17 at 08:46
  • Sorry, don't know about that. I'm not really using TS myself. – Günter Zöchbauer Feb 28 '17 at 08:50
  • http://stackoverflow.com/questions/33305954/typescript-export-vs-default-export/33307487#33307487 also doesn't say anything about effectiveness. I guess it won't make a difference. – Günter Zöchbauer Feb 28 '17 at 08:53