首页 > 解决方案 > 如何访问由调用组件以角度绑定的对象的属性?

问题描述

组件定义:

...
...= {'a':1}
```

在模板中:

...
{{test|json}}
{{test.a}}
...

输出:

{ "a": 1 }

一切都是对的。但我想从另一个组件绑定属性测试:

组件定义:

...
@Input()
test = {}
...

在根组件/模板中:

...
<test-component [test]="{'a':1}"></test-component>
...

在模板中:

...
{{test|json}}
...

输出:

{ "a": 1 }

在模板中:

...
{{test|json}}
{{test.a}}
...

输出:

**ERROR:  error TS2339: Property 'a' does not exist on type '{}'**  

为什么该属性a无法访问,我该如何解决?

标签: angular

解决方案


推荐阅读