[英]why Input attribute in angular is not taking the value that I sent by the html file?
Hello everyone I have this problem related to Angular.大家好,我有这个与 Angular 相关的问题。
inside my skills.component.ts.在我的技能.component.ts 中。
@Input() testfield ="";
inside skills.component.html里面的skills.component.html
style="padding: 0 10%"
class="row align-items-center">
<p id="skill"
class="col-2"
style="font-family: Mulish-Bold, serif; font-size: 1.2rem; text-align: end;"
>
{{testfield}}
</p>
<p class="col-7" id="bar">
<ngb-progressbar
type="success"
[value]="50">
</ngb-progressbar>
</p>
</div>
and inside the component that uses this app-skill-bar .并在使用此app-skill-bar的组件内部。
<app-section-title color="#84142D" icon="bi bi-star-fill" title="Skills"></app-section-title>
<app-skill-bar testfield="Android"></app-skill-bar>
</div>
the problem is that angular can't take "Android" as value for testfield.问题是 angular 不能将“Android”作为测试字段的值。 also, it doesn't desplay Android.
此外,它不会显示 Android。
I checked your project.我检查了你的项目。 The input works correctly.
输入正常工作。 The problem is that you create in app.module.ts two independent components trees.
问题是您在 app.module.ts 中创建了两个独立的组件树。 The first time a component is loaded, the value "Android" exists, but then the component is quickly reloaded with no value passed.
第一次加载组件时,值“Android”存在,但随后组件快速重新加载,没有传递任何值。 You can analyze this by putting the debugger in ngOnInit method in your SkillBarComponent.
您可以通过将调试器放在 SkillBarComponent 的 ngOnInit 方法中来分析这一点。 All in all, you should remove SkillBarComponent from the bootstrap array.
总而言之,您应该从引导数组中删除 SkillBarComponent。
Since you added SkillBarComponent in bootstrap array, it will be considered as root component and You are passing an input in the root component, which will not work.由于您在引导数组中添加了 SkillBarComponent,它将被视为根组件,并且您在根组件中传递了一个输入,这将不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.