我正在尝试将一个参数(哈希对象)从我的一个页面传递给一个组件。
我可以从组件的视图中访问该对象。但我想要的是首先从代码(.ts
)中读取它,然后传递给视图。
这是我的代码
#main page component
<selected-options [node]="node"></selected-options>
#selected-options component code
import { Component, Input } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
@Component({
selector: 'selected-options',
templateUrl: 'build/components/selected-options/selected-options.html',
inputs: ['node']
})
export class SelectedOptions {
@Input() node: any;
private selectedNodes: any;
constructor(public ryvuss: Ryvuss, public nav: NavController, public navParams: NavParams) {
// I want to read the node object in here
this.node = navParams.get('node');
this.selectedNodes = //dosomething with node
}
}
#selected-options component html view
<div *ngFor="let selected of selectedNodes">
//loop
</div>
如果我从视图中直接访问该节点,它将工作<div *ngFor="let selected of node">
但是如何从组件代码本身访问传递给组件的参数呢?