Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2, split components in different files

Tags:

angular

I m actually making the angular.io quickstart and I need now to split my component into different files.

The problem is that I dont know at all how to do it, and it's not explained in the dev preview doc.

Can you help ?

I simply have two components (the main in app.js, and another one which only list informations)

Thanks for advance

like image 747
mfrachet Avatar asked May 18 '15 08:05

mfrachet


1 Answers

Agree, this is not well explained and a lot of examples only use a single component or components in a single file. This is an example I am building which uses (currently) 2 components in separate files and is about as simple as I can make it...

https://github.com/mdausmann/angular2-canvas

Essentially, you need to export the sub-component from it's module...

export default NoteComponent;

and import it into the composing or parent module...

import NoteComponent from "note";

Oh, this import/export thing is ES6 module syntax, great ref here

Hope this helps.

like image 195
Michael Dausmann Avatar answered Sep 22 '22 12:09

Michael Dausmann