Angular 4中@Input('someValue')和@Input()的装饰器语法有什么区别?

3
我之前并没有清楚两种语法的区别,谢谢您提前帮忙解答。
2个回答

4

@Input() 不会有任何别名。

  • Example

     @Input() student:any[];
     <component [student]="...">
    

@Input('someValue')会将别名作为someValue

  • Example

    @Input('studentInfo') student:any[];
    
    <component [studentInfo]="...">
    
当您使用别名时,请确保在HTML模板中使用该别名。

@JustinCastillo 很高兴能帮助你。 - Aravind

1
除了 @Aravind 的帖子之外,@Output 和 @ViewChild 指令也是如此。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接