【发布时间】:2019-05-29 13:15:31
【问题描述】:
我有一个组件,其中有flagPerfil 变量,我需要将此变量发送到我的模块。
我的服务
export class ListUserService {
public flagPerfil = boolean;
changeFlagPerfil() {
console.log('EEE' + this.flagPerfil);
this.flagPerfil ? this.flagPerfil = false : this.flagPerfil = true;
}
组件类:
@Component({
selector: 'app-list-user',
templateUrl: './list-user.component.html',
styleUrls: ['./list-user.component.scss'],
providers: [ListUserService]
})
export class ListUserComponent implements OnInit {
private flagPerfil = false;
getFlag() {
return this.flagPerfil;
}
这是视图 list-user.component.html
<span *ngIf="!flagPerfil">
<input type="button" id="usuarios" name="more" (click)="changeFlagPerfil()"
value="Amigos">
</span>
我有一个模块,我想在模块中注入服务,因为
我需要FlagProfile 变量
@NgModule({
imports: [
IonicModule,
CommonModule,
FormsModule,
RouterModule.forChild([{path: '', component: Tab1Page}])
],
declarations: [Tab1Page, ListUserComponent, FriendsComponent]
})
export class Tab1PageModule {
public flagPerfil: boolean;
constructor(private listUserService: ListUserService) {
this.flagPerfil = listUserService.flagPerfil;
console.log('FLAG', listUserService.flagPerfil);
}
}
如何使用事件 Emit?
我需要模块自动听到那个变量的变化
【问题讨论】:
-
不要使用服务等模块。我不明白为什么需要在构造函数中完成。
-
@Reactgular 我需要使用模块,我需要 flagPerfil 的值
-
@Reactgular 我不将模块用作服务,我有组件的服务