2

このコードを使用すると、私はasp mvcで角2を使用しました。ページが角2に見つかりませんでした。asp mvc

私はこのコードを使用すると問題なく動作します。

app.module:

import { NgModule } from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 

import { AppComponent } from './app.component'; 
@NgModule({ 
    imports: [BrowserModule], 
    declarations: [AppComponent], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

がapp.component:

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

@Component({ 
    selector: 'my-app', 
    template: '<h1>My First App</h1>' 
}) 
export class AppComponent { 
} 

ヘッダで:

<head> 
<meta charset="utf-8" /> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<title>@ViewBag.Title - My ASP.NET Application</title> 
<base href="/" /> 
<link rel="stylesheet" href="/styles.css"> 
<!-- Polyfill(s) for older browsers --> 
<script src="/node_modules/core-js/client/shim.min.js"></script> 
<script src="/node_modules/zone.js/dist/zone.js"></script> 
<script src="/node_modules/reflect-metadata/Reflect.js"></script> 
<script src="/node_modules/systemjs/dist/system.src.js"></script> 
<script src="/systemjs.config.js"></script> 
<script> 
    System.import('app').catch(function(err){ console.error(err); }); 
</script> 
@Styles.Render("~/Content/css") 
@Scripts.Render("~/bundles/modernizr") 

このコードは仕事です。それは私の目に見える:My First App

が、私はこのコードを使用するとき、それは私にエラーを示しています。

app.module:

import { NgModule } from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 

import { AppComponent } from './app.component'; 
import { OtherComponent } from './other/other.component'; 

@NgModule({ 
    imports: [BrowserModule], 
    declarations: [AppComponent, OtherComponent], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

app.component:

import { Component } from '@angular/core'; 
import { OtherComponent } from './other/other.component'; 

@Component({ 
    selector: 'my-app', 
    template: `<h1>My First App</h1> 
       <other-app></other-app> 
` 
}) 
export class AppComponent { 
} 
私はこのコードを使用し

Error

other.component:

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

@Component({ 
    selector: 'other-app', 
    templateUrl: 'app/other/other.component' 
}) 
export class OtherComponent implements OnInit { 
    Constractor() { } 
    ngOnInit(){ } 
} 

other.component.html:

<div class="panel panel-default"> 
    <div class="panel-body"> 
     {{name}} 
    </div> 
</div> 

いただきまし通報しますか?どうすればこの問題を解決できますか?

答えて

1

templateUrl: 'app/other/other.component'

'app/other/other.component.html' 
での.html形式を追加します
関連する問題