How does Angular2 import its components?

后端 未结 2 876
感情败类
感情败类 2021-01-23 11:52

I am pretty new to AngularJS 2.0. When I read its quickstart guide and some other posts, there are import lines like this:

import {Component, View,          


        
相关标签:
2条回答
  • 2021-01-23 12:00

    As mentioned by @Guenter, angular2/angular2 is not any path - rather, it is a predefined bundle of Angular2. For this we have already imported system.js before our angular in the index.html file.

    If you look at the source code of Angular, you can see System.register("angular2/core", .... and that tells systemjs what to do. You can find out more here.

    As Angular2 is no longer in beta, angular2/angular2 does not exist.

    Now, according to all of the updates, the list of imports is here:

    import {Component, View, Directive, Input, Output, Inject, Injectable, provide} from 'angular2/core'; 
    
    import {bootstrap} from 'angular2/platform/browser';
    
    import {CORE_DIRECTIVES, FORM_DIRECTIVES, NgClass, NgIf  NgForm, 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'
    
    0 讨论(0)
  • 2021-01-23 12:21

    Here 'angular2/angular2' is not a path but a predefined systemjs bundle for angular. In your index.html you have to load the system.js script ahead of angular.

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