Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't import Angular2 bootstrap method

I'm trying to boot up basic Angular 2 (beta 2) app with TypeScript. I have the following app.ts file (copied from Angular's latest setup guide)

import {Component, View, bootstrap} from 'angular2/angular2';
@Component({
    selector: 'app'
})
@View({
    template: `
        <div></div>
    `
})
class AppComponent {
    constructor() {}
}

bootstrap(AppComponent);

but when I try to compile it, I get error

Error TS2307: Cannot find module 'angular2/angular2'.

If I instead use the format found on some other resources with angular2/core instead of angular2/angular2 like

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

I get error

Error TS2305: Module '"node_modules/angular2/core"' has no exported member 'bootstrap'.

What should I do to import all of them?

like image 824
Roope Hakulinen Avatar asked Mar 13 '23 10:03

Roope Hakulinen


2 Answers

The bootstrap was moved from angular2/angular2 to angular2/platform/browser so you need to use it as

import {Component, View} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
like image 60
Roope Hakulinen Avatar answered Mar 25 '23 07:03

Roope Hakulinen


As of Angular2 alpha-53 list of imports has been changed from normal angular2/angular2

Since Angular2 alpha-53 bootstrap can be imported from angular2/platfrom/browser.

Here is list of all imports may help to someone else.

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

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

import{CORE_DIRECTIVES,FORM_DIRECTIVES,NgClass,NgIfNgForm,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'

Breaking change for import list https://github.com/angular/angular/blob/master/CHANGELOG.md#200-alpha53-2015-12-13

like image 30
Pardeep Jain Avatar answered Mar 25 '23 07:03

Pardeep Jain