[英]Is it possible to use a component inside another component with some modification
I have a home component and inside the Home component I am using the login component. 我有一个home组件,在Home组件中我正在使用登录组件。
There is another component named My Account and I have to use the login component in my account page as well. 还有另一个名为“我的帐户”的组件,我也必须在帐户页面中使用登录组件。 But I cannot use this login component inside the my account component without adding 'current' class <div id="tab-3" class="log-tab-content current">
because its a popup and adding the current class makes the popup to show so it will be hidden if I dont add current class. 但我不能在我的帐户组件中使用此登录组件而不添加“当前”类<div id="tab-3" class="log-tab-content current">
因为它的弹出窗口并添加当前类会弹出显示所以如果我不添加当前类,它将被隐藏。 In the home page you have to click to view the login popup (component), thats how it gets activated. 在主页中,您必须单击以查看登录弹出窗口(组件),这就是如何激活它。 How could I reuse the component in this case ? 在这种情况下,我如何重用组件?
<form [formGroup]="LoginForm" (ngSubmit)="onSubmit()">
<div id="tab-3" class="log-tab-content">
<div class="login-form">
<div class="login-mid">
</div>
<input type="text"/>
</div>
<button type="submit" class="log-button log-button1">Reset Password</button>
</div>
</div>
</form>
Yes, @Input()
properties are meant for that. 是的, @Input()
属性就是为了这个。 You can change the behavior of component based on the input values. 您可以根据输入值更改组件的行为。
current
class dynamically using ngClass
based on some input
property sent by parent. 根据父发送的某些input
属性,使用ngClass
动态设置current
类。 login
comp from my-account
like [showPopup]="true"
. 将输入发送到my-account
login
comp,如[showPopup]="true"
。 Code: 码:
login comp ts 登录组合
class LoginComponent{
@Input() showPopup: boolean = false;
}
login.html 的login.html
<form [formGroup]="LoginForm" (ngSubmit)="onSubmit()">
<div id="tab-3" class="log-tab-content" [ngClass]="{'current':showPopup === true}">
<div class="login-form">
<div class="login-mid">
</div>
<input type="text"/>
</div>
<button type="submit" class="log-button log-button1">Reset Password</button>
</div>
</div>
</form>
my-account 我的帐户
<login [showPopup]="true"></login>
I think you could just wrap the login component in some dialect component(material dialect for example) instead of using customer class in order to change the css. 我认为您可以将登录组件包装在某个方言组件(例如材料方言)中,而不是使用客户类来更改css。 Then you are free to reuse your component. 然后您可以自由地重用您的组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.