2017-10-22 7 views
0

角度4のaspコア2.0の新機能です。 角度2ではディレクティブを使用していましたが、角度4ではapp.component.ts内のコンポーネントを使用するのに役立ちます無指向これ以上角度4のネストされたコンポーネントaspコア2.0

手助けコード:

app.component.ts

import { Component } from '@angular/core'; 
@Component({ 
    selector: 'app', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { 
} 

app.component.html

<div class='container-fluid'> 
    <div class='row'> 
     **<mycomponentname></mycomponentname>** 
    </div> 
</div> 

これはエラーになります:テンプレート解析エラー: 'mycomponentname'は既知の要素ではありません: 1. 'mycomponentname'がAngularコンポーネントの場合は、それがこのモジュールの一部であることを確認してください。

答えて

0

他のコンポーネントを作成する必要があると思います。

import { Component } from '@angular/core'; 
@Component({ 
    selector: 'mycomponentname', 
    templateUrl: './mycomponentname.component.html', 
    styleUrls: ['./mycomponentname.component.css'] 
}) 
export class MyComponent { 
} 

と単にあなたがおかげで、Visual Studioのテンプレートで何app.module.tsがないと述べたまさにapp.component.ts

import { Component } from '@angular/core'; 

// If they in the same direction 
// import { ClassName } from 'direction of TS file without .ts extension' 
    import { MyComponent } from './mycomponent'; /// <<<---- 

@Component({ 
    selector: 'app', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { 
} 
+0

にインポートします。代わりに、私はapp.module.shared.tsに自分のコンポーネントを追加して動作します –

関連する問題