Angular2以打字稿:导入组件到组件

问题描述 投票:2回答:1

我试图导入组件我做,到主要成分,但它不是正确渲染仅<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代码IDE IM

{

"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>
typescript angular angular2-directives angular2-template
1个回答
5
投票

您需要提供链接到文件,如:

import {eye} from './eyeComponent';       //importing components
import {hair} from './hairComponent' ;
© www.soinside.com 2019 - 2024. All rights reserved.