简体   繁体   English

Angular 2 通过 HTML 将参数传递给组件

[英]Angular 2 passing parameter to component through HTML

I'm new to Angular 2 and I'm facing a difficulty in passing a parameter to component through HTML..I made some researches and I applied them but nothing worked我是 Angular 2 的新手,我在通过 HTML 将参数传递给组件时遇到了困难..我做了一些研究并应用了它们,但没有任何效果

import { Component,Input } from '@angular/core';
@Component({

  //  inputs: ['value : value'], // I tried this too

    template: `<h1>{{value}}</h1>
  <br> <p>  Hello Angular2 </p>
<hr>
  `,
})

    export class AppComponent {

@Input('value') value: string;
}

and I called my component in index.html like this我像这样在 index.html 中调用了我的组件

<symfony-loves-angular [value]="user">Let me think...</symfony-loves-angular>

but it only showed Hello Angular2, and didn't show the {{value}} that I passed!但它只显示Hello Angular2,并没有显示我通过的{{value}}!

Thank you in advance :) I really appreciate your help !在此先感谢您 :) 我非常感谢您的帮助!

Did you try...你试过了吗...

export class AppComponent {
  ...
  constructor(value) {
    this.value = value;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM