我有两个组件类A和B.从另一个组件类访问组件类变量
由于注入许多服务,A类有一个很大的构造函数。和在B类等
IonicPage()
@Component({
selector: 'page-chat',
templateUrl: 'chat.html',
providers: [ChatService]
})
export class ChatPage implements OnInit, OnDestroy{
msg:any[];
阵列这就好比是
@Component({
selector: 'page-home',
templateUrl: 'home.html',
providers: [ChatService]
})
export class HomePage {
chatRoot = ChatPage;
settingsRoot = SettingsPage;
constructor(private chatService: ChatService) {
}
onReset(){
//this.chatRoot.msg = [];
}
}
另一个分量i希望重置MSG为[]。在当前状态,我得到complan,我的味精是未知的,
你不会在其他组件的组件分配给变量,你可以在homePage中执行ViewChild和实例,或为msg创建模型 – alehn96