简体   繁体   English

为什么 angular 中的输入属性没有采用我通过 html 文件发送的值?

[英]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.

相关问题 Angular2通过html模板动态地将属性值传递为@input - Angular2 Pass attribute value dynamically from html template as @input Angular HTML Forms - 值属性在输入字段中不起作用 - Angular HTML Forms - value attribute not working in input field 输入变量不从模板的@Input属性中获取值。 Angular 5 - Input variable not taking value from @Input property at template. Angular 5 Angular:如果没有输入,则不显示 HTML 属性 - Angular: Do not Display HTML Attribute if No Input angular2中的HTML输入值 - HTML Input value in angular2 Angular2 - 为什么我的带有 html 模式属性的反应式表单输入无法正确验证? - Angular2 - Why does my reactive form input with an html pattern attribute is not validating correctly? 为什么我不能用 Angular NgModel 限制输入的值长度? - Why I can not limit an input's value length with Angular NgModel? Angular 2 - 根据输入值在模板中添加属性 - Angular 2 - add attribute in template based on input value 如何对[自动对焦]的属性(属性)使用属性绑定 <input> HTML文件中的标签标记为Angular中的布尔变量 - How to use property binding for [autofocus] attribute (property) of <input> tag in HTML file to a boolean variable in Angular Angular ngmodel 忽略表单输入中的值属性 - Angular ngmodel ignores value attribute in a form input
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM