【发布时间】:2016-04-27 20:40:35
【问题描述】:
我正在学习 angularjs2,和/也在使用 ionic 2! 在 ionic 中,我在以下位置创建了一个侧边菜单:
/app.html:
<ion-content>
<ion-item-group>
<ion-item-divider light>Cats</ion-item-divider>
<ion-item *ngFor="#cat of categories" (click)="filter('category', cat.id)">{{cat.name}}</ion-item>
</ion-item-group>
当我点击这些类别中的任何一个时,我想将类别 ID 发送到我的一个页面(主页)。
我正在尝试将值设置为 app.js 中的 HomePage 类:
filter(key, value){
HomePage.prototype.setFilters(value); }
然后读取 HomePage 类中的值:
/home/home.js:
setFilters(value) {
this.ViewValue = value;
console.log(this.ViewValue);
}
问题是,无法在主页视图中打印该值。 我正在尝试: /home/home.html:
<ion-content class="getting-started">
Selected category:
{{ViewValue}}
</ion-content>
当我单击左侧菜单中的任何类别时,ViewValue 不会改变。 当我运行 console.log 时,我可以获得我的类别,但它不会在视图中改变。
我做错了什么? 还是有更好的方法?
【问题讨论】: