Angular 4 个嵌套组件 asp 核心 2.0
Angular 4 nested component with asp core 2.0
我是 asp 核心 2.0 和 angular 4 的新手。
任何人都可以帮助我在 app.component.ts 中使用组件,因为我在 angular 2 中使用指令,但在 angular 4 中没有指令了
帮助代码:
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 组件,那么验证它是这个模块的一部分。
我想您只需要创建另一个组件。
import { Component } from '@angular/core';
@Component({
selector: 'mycomponentname',
templateUrl: './mycomponentname.component.html',
styleUrls: ['./mycomponentname.component.css']
})
export class MyComponent {
}
并简单地导入 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 {
}
我是 asp 核心 2.0 和 angular 4 的新手。 任何人都可以帮助我在 app.component.ts 中使用组件,因为我在 angular 2 中使用指令,但在 angular 4 中没有指令了
帮助代码:
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 组件,那么验证它是这个模块的一部分。
我想您只需要创建另一个组件。
import { Component } from '@angular/core';
@Component({
selector: 'mycomponentname',
templateUrl: './mycomponentname.component.html',
styleUrls: ['./mycomponentname.component.css']
})
export class MyComponent {
}
并简单地导入 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 {
}