我从 Angular 开始,完成了教程,试图掌握概念,但我遇到了一个看似简单的问题。试图用谷歌搜索,但我无法解决这个问题。
在 Angular 5 中,您将如何在组件之间重用属性(此处为标题)?假设我title定义了app.component.ts我希望最终在login.compoment.html??中重用的属性
app.module.ts
@NgModule({
imports: [
AppRoutingModule
],
declarations: [
AppComponent,
LoginComponent,
],
providers:[
// services
],
bootstrap: [AppComponent]
})
export class AppModule {}
app.component.ts
@Component({
selector : 'app-root',
template : `<router-outlet></router-outlet>`
})
export class AppComponent {
title = 'A global title...';
}
登录组件.ts
@Component({
selector : 's-login-pg',
templateUrl: './login.component.html',
styleUrls : [ './login.scss'],
})
export class LoginComponent implements OnInit {
// should title be referenced here?
// should the AppComponent be imported again, as they are already both defined in app module ?
}
login.component.html
<div>{{title}}</div> <!-- I want the title in app.component.ts to show up -->
你能建议如何处理这个问题吗?