Kuan
Kuan

Reputation: 11389

TypeScript import from

All:

When I read "Angular2 5mins start"-Tutorial, the first syntax confuses me:

import {bootstrap, Component} from 'angular2/angular2';

I wonder where can I find this syntax from TypeScript (I only find import, but not import...from)?

Thanks

Upvotes: 1

Views: 644

Answers (2)

CoderPi
CoderPi

Reputation: 13211

This Syntax was added in ES6 for JavaScript, here is the complete list and explanation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

import { member1 , member2 } from "module-name";

... is the one you found in your Tutorial.

  • member, memberN Name of the exported members to be imported.
  • module-name The name of the module to import. This is a file name.

Note that this ES6-JavaScript feature is not supported in any Browser as of today. But TypeScript / AngularJS will deal with it.


There was no such syntax in the original TypeScript. Here is the TyepScript Handbook about import: http://www.typescriptlang.org/Handbook#modules-going-external

Upvotes: 1

Heretic Monkey
Heretic Monkey

Reputation: 12114

That syntax is for ES2015, also known as ES6. Basically, it lets you decide what to import from the external files. See some documentation or the standard itself if you need some light reading.

Upvotes: 1

Related Questions