【发布时间】:2020-07-05 15:53:32
【问题描述】:
我想将静态值从 html 传递给组件,但它不起作用,我整天都被卡住了......你能给我一些胶水吗?谢谢
组件:
import { Component, Input } from '@angular/core';
@Component({
selector: 'rio-hello',
template: `<p>Hello, {{name}}!</p>
<button (click)="greet()">Show Greet</button>
`,
})
export class HelloComponent {
@Input()
name: string;
greet(){
console.log(`Hello,${name}`);
}
}
入口html index.html
<rio-hello name="World"></rio-hello>
我期待的是它可以在页面上打印Hello, World,并且可以在组件中将name属性设置为World,如何实现?
【问题讨论】:
标签: angular