最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to pass variable into component properites in Angular - Stack Overflow

programmeradmin2浏览0评论

So i have such main component

<div class="wrapper">
  // some code here
    @if (isLogin()){
      // some code if isLogin is true
    }
</div>

in my component.ts i have declared it as InputSignal set to false

export class AuthComponentComponent implements OnInit{
  title= input.required<string>();
  buttonText = input.required<string>();
  linkText = input.required<string>();
  linkUrl = input.required<string>();
  isLogin = input<boolean>(false);
  // ...
}

Then i create components based on this like so

<app-auth-component
  title="Zaloguj się"
  buttonText="Zaloguj się"
  linkText="Lub utwórz nowe konto!"
  linkUrl="/register">
  (formSubmit)="handleLogin($event)">
</app-auth-component>

at first i tried to just add

<app-auth-component
  //...
  [isLogin]="true"
</app-auth-component>

but it does not work, it does not change the value of isLogin with creation of component. Any ideas?

So i have such main component

<div class="wrapper">
  // some code here
    @if (isLogin()){
      // some code if isLogin is true
    }
</div>

in my component.ts i have declared it as InputSignal set to false

export class AuthComponentComponent implements OnInit{
  title= input.required<string>();
  buttonText = input.required<string>();
  linkText = input.required<string>();
  linkUrl = input.required<string>();
  isLogin = input<boolean>(false);
  // ...
}

Then i create components based on this like so

<app-auth-component
  title="Zaloguj się"
  buttonText="Zaloguj się"
  linkText="Lub utwórz nowe konto!"
  linkUrl="/register">
  (formSubmit)="handleLogin($event)">
</app-auth-component>

at first i tried to just add

<app-auth-component
  //...
  [isLogin]="true"
</app-auth-component>

but it does not work, it does not change the value of isLogin with creation of component. Any ideas?

Share Improve this question asked Feb 7 at 13:34 Hubert KiszkaHubert Kiszka 192 bronze badges 1
  • Cannot reproduce with a simplified version of your code in StackBlitz. – JSON Derulo Commented Feb 7 at 13:38
Add a comment  | 

1 Answer 1

Reset to default 0

Make sure you imported the AuthComponentComponent into the imports array of the component that uses it.

@Component({
  ...
  imports: [
    ...
    AuthComponentComponent,
    ...
  ]
})
export class ComponentThatUsesAuth {
  ...
发布评论

评论列表(0)

  1. 暂无评论