0
我尝试使用AngularJS 2创建组件。它工作正常,但我不确定如何将值作为绑定传递。 下面是代码:AngularJS 2访问模板中传递的绑定
(function(app) {
app.AppComponent =
ng.core.Component({
selector: 'my-app',
templateUrl: './app/grid.htm',
bindings:{
info:'=info'
}
})
.Class({
constructor: function() {
this.items = [
{ id: 1, name: 'Roy', age: 25 },
{ id: 2, name: 'James', age: 30 }
];
}
});
})(window.app || (window.app = {}));
从我传递中的项目在构造函数中的视图部分:
<my-app info="items">Loading...</my-app>
但我不能够访问它在模板templateUrl: './app/grid.htm',
这里是模板代码:
<tr *ngFor='#item of info'>
<td>
<span>{{ item.name }}</span>
</td>
<td>
<span>{{ item.age }}</span>
</td>
</tr>
但它不是WO rking。任何一个可以指出什么可能是错误的?
我可以知道'ref.nativeElement.getAttribute('mydata')'是否会理解他需要从'this.items'中获取'mydata',而不是从'attribute'中获取? –
如何将使用属性将外部组件加载到组件的方式传递给组件? – iJade