Javascript 角度@输入装饰器
您好,学习angular时遇到了angular中的@input decorators。在研究了这个主题之后,我仍然很难理解这个概念 代码: app.component.html: tutorial.component.html: 问题: 我目前的理解是否正确?此外,如果您在回答我忽略的问题时有其他信息,或者可能对本主题有所帮助,我将不胜感激Javascript 角度@输入装饰器,javascript,angular,typescript,Javascript,Angular,Typescript,您好,学习angular时遇到了angular中的@input decorators。在研究了这个主题之后,我仍然很难理解这个概念 代码: app.component.html: tutorial.component.html: 问题: 我目前的理解是否正确?此外,如果您在回答我忽略的问题时有其他信息,或者可能对本主题有所帮助,我将不胜感激 @input仅用于将数据从父组件传输到子组件 我们使用属性绑定:在应用程序教程组件中传递foo的数据 然后,我们可以使用@input在tutorials.
仅用于将数据从父组件传输到子组件@input
- 我们使用属性绑定:
在应用程序教程组件中传递
的数据foo
- 然后,我们可以使用
在tutorials.component.ts文件中使用这些数据@input
- 使用字符串插值,我们只能从它自己的ts文件绑定变量,但由于我们现在使用了
,我们也可以在这个HTML模板中使用它@input
<app-tutorials [bar]="foo"></app-tutorials>
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
foo = {
name: 'willem',
}
}
<p>{{bar.name}}</p>
import { Component, OnInit, Input} from '@angular/core';
@Component({
selector: 'app-tutorials',
templateUrl: './tutorials.component.html',
styleUrls: ['./tutorials.component.css']
})
export class TutorialsComponent{
@Input() bar
}