[英]how to use setter and getter from html page in ionic 2
I am in the need to set a value (variable) and get change after performing some specific task. 我需要设置一个值(变量)并在执行某些特定任务后得到更改。
I would like to share my system environment, which is as below- 我想分享我的系统环境,如下所示-
******************************************************
Your system information:
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-beta.10
Ionic CLI Version: 2.1.8
Ionic App Lib Version: 2.1.4
ios-deploy version: Not installed
ios-sim version: 5.0.8
OS: OS X Yosemite
Node Version: v6.2.2
Xcode version: Xcode 7.2 Build version 7C68
******************************************************
I wanted to use setter and getter to get this task done, see what i did- 我想使用setter和getter来完成此任务,看看我做了什么-
mypage.ts- mypage.ts-
import {NavController, NavParams, Content} from 'ionic-angular';
export class ListPage {
constructor(private navCtrl: NavController, navParams: NavParams) {
this.counter = 0;
}
public counter;
getCounter(){
return this.counter;
}
setCounter(count) {
this.counter = count;
// console.log(this.counter);
}
}
and this is html template as- 这是html模板-
<div *ngIf= "( getCounter()== '0')">
.....
...
..
...
.....
</div>
<div (click)= (setCounter(getCounter()+1))
</div>
some= line of codes
....
....
....
on bottom
<div ( setCounter(0))>
</div>
I am able to get the value which is 0, but don't know how to set it. 我可以得到 0 的值 ,但不知道如何设置它。 I want to set value without (click) even i have used click but i don't know how to do without click .
即使我已经使用click,我也想设置没有click的 值 ,但是我不知道如何没有click 。
here are list of source URL which I have seen- 这是我看到的源URL列表-
Hope for help 希望得到帮助
See the link get and set in TypeScript 请参阅在TypeScript中获取和设置的链接
get Counter(){
return this.counter;
}
In HTML 在HTML中
<div *ngIf="Counter== '0'">
<div (click)= "setCounter(Counter+1)>"
This example below will increase the counter
each time the page is visited. 每次访问页面时,下面的示例将增加
counter
。 ionViewDidEnter
will be called each time page is viewed. 每次查看页面时,都会调用
ionViewDidEnter
。 Hope this is what you are lloking for. 希望这就是你所追求的。
export class ListPage {
constructor(private navCtrl: NavController, navParams: NavParams) {
this.counter = 0;
}
public counter;
ionViewDidEnter(){
this.setCounter(this.getCounter() + 1 ) ;
}
getCounter(){
return this.counter;
}
setCounter(count) {
this.counter = count;
// console.log(this.counter);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.