Angular2 с TypeScript: импорт компонентов в компоненты

Я пытаюсь импортировать компонент, который я сделал, в основной компонент, но он не отображается правильно, в браузере отображается только <helloworld>Testing...</helloworld>

это мой основной файл component.ts:

import {bootstrap} from 'angular2/platform/browser';
import {Component, View} from 'angular2/core';
import {eye} from 'eyeComponent';       //importing components
import {hair} from 'hairComponent' ;

@Component({
selector : 'helloworld',
directives : [hair, eye]
});

@View({
template : `<div>
            <hair></hair>
            <eyes></eyes>
            </div>
`
  })
export class helloworld {

}

bootstrap(helloworld);

Вот мой файл компонента, который я импортировал

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

@Component({
selector : 'eyes',
template : `<h1> eyes </h1>`
});

export class eye{

}

bootstrap(eye);

Вот еще один файл component.ts:

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

@Component({
selector : 'hair',
template : '<h2>Hair Component <h2>'
});

export class hair{

}

bootstrap(hair);

и это tsconfig, я использую vs code ide

{

"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]

}

А вот html файл

<html>
<head>
    <title>Angular2 App</title>
     <script src="node_modules/es6-shim/es6-shim.js"></script>
     <script src="node_modules/es6-promise/dist/es6-promise.js"></script>
     <script src="node_modules/angular2/bundles/angular2-polyfills.js">

     </script>
     <script src="node_modules/systemjs/dist/system.src.js"></script>
     <script src="node_modules/rxjs/bundles/Rx.js"></script>
     <script src="node_modules/angular2/bundles/angular2.dev.js"></script>

     <script>
        System.config({
            packages : {
                app : {
                    format : 'register',
                    defaultExtension : 'js'
                }
            }
        });
        System.import('app/app').then(null, console.error.bind(console));
     </script>


    </head>
    <body>

    <helloworld>Testing...</helloworld>

    </body>
    </html>

person blackHawk    schedule 15.01.2016    source источник
comment
какая у вас структура папок? в операторе импорта необходимо указать относительный путь к импортируемому компоненту. если они находятся в одной папке, это должно быть: ./eyeComponent, где eyeComponent — это имя файла, из которого вы хотите импортировать.   -  person toskv    schedule 15.01.2016
comment
См. обновленный вопрос   -  person blackHawk    schedule 15.01.2016
comment
Ответ Саймона исправит это. :)   -  person toskv    schedule 15.01.2016


Ответы (1)


Вам нужно будет предоставить ссылки на файлы, например:

import {eye} from './eyeComponent';       //importing components
import {hair} from './hairComponent' ;
person Simon H    schedule 15.01.2016
comment
Я играл вокруг, безуспешно - person blackHawk; 15.01.2016