我是asp核心2.0中的新成员,有角4。有人能帮我使用app.component.ts内部的组件吗?就像我在角2中使用指令一样,但是在角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’是一个角组件,那么验证它是这个模块的一部分。
发布于 2017-10-24 07:49:20
我想你只需要创建另一个组件。
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 {
}https://stackoverflow.com/questions/46877874
复制相似问题