# How does conditional works?

**URL:** <https://discuss.emberjs.com/t/how-does-conditional-works/6674>\
**Category:** Uncategorized\
**Created:** [November 12, 2014, 7:24am UTC](https://discuss.emberjs.com/t/how-does-conditional-works/6674 "2014-11-12T07:24:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laipak](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/laipak/32/9821_2.png) [@Laipak](https://discuss.emberjs.com/u/Laipak)\
**Post date:** [November 12, 2014, 7:24am UTC](https://discuss.emberjs.com/t/how-does-conditional-works/6674/1 "2014-11-12T07:24:35Z")

</div>

Hi guys, i’m new and like to get some help.   
I got two buttons which will execute next and previous function when clicked in the {{if}} statement.  
  
So basically if it is the last page, next button will hide, and previous button will hide in the first page.  
  
But after trying, seems like the view only render once, so the new boolean is not being read, and thus the buttons is not hid even the boolean is false.  
  
And btw how can I call the function in the same controller?  
Like calling bgImg in actions.next,  
I tried _**this.send(‘bgImg’);**_ but no luck.  
  
 Any help is appreciated.

Codes below:

_template.hbs_

```
{{#if notMin}}
  <button {{action 'previous'}}></button>
{{/if}}
{{#if notMax}}
  <button {{action 'next'}}></button>
{{/if}}

```

_controller.js_

```
App.ApplicationController = Ember.Controller.extend({
  frameIndex: 1,
  frameSize: 5,
  notMin: false,
  notMax: true,

  actions: {
    next: function(){
      this.notMin = true;

      if(this.frameIndex>=this.frameSize){
        console.log("Last page reached!");  
      }else if(this.frameIndex==this.frameSize-1){
        this.frameIndex++;
        this.notMax = false;
      }else{
        this.frameIndex++;
      }
   },

   previous: function(){
     this.notMax = true;

     if(this.frameIndex==1){
       console.log("First page reached!");  
     }else if(this.frameIndex==2){
       this.frameIndex--;
       this.notMin = false;
     }else{
       this.frameIndex--;
     }
   }
 },

   bgImg: function(){
     var head = "background-image:url('images/";
     var img = jsondata[this.frameIndex-1].bgimg;
     var end = "')";
     return head+img+end;
   }.property('frameSize'),
});

```

---

<div class="post-metadata">

**Author:** ![splattne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/splattne/32/3694_2.png) [@splattne](https://discuss.emberjs.com/u/splattne)\
**Post date:** [November 12, 2014, 7:30am UTC](https://discuss.emberjs.com/t/how-does-conditional-works/6674/2 "2014-11-12T07:30:30Z")

</div>

Don’t forget to use .get and .set on Ember object properties.

```
this.set('notMin', true);
[...]
this.set('notMax', false);
[...]
if (this.get('frameIndex') == ...

```

etc.

---

<div class="post-metadata">

**Author:** ![Laipak](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/laipak/32/9821_2.png) [@Laipak](https://discuss.emberjs.com/u/Laipak)\
**Post date:** [November 12, 2014, 7:34am UTC](https://discuss.emberjs.com/t/how-does-conditional-works/6674/3 "2014-11-12T07:34:48Z")

</div>

Work like a charm,  
thanks a lot Splattne!

---

<div class="post-metadata">

**Author:** ![splattne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/splattne/32/3694_2.png) [@splattne](https://discuss.emberjs.com/u/splattne)\
**Post date:** [November 12, 2014, 8:01am UTC](https://discuss.emberjs.com/t/how-does-conditional-works/6674/4 "2014-11-12T08:01:27Z")

</div>

You’re welcome! Bonus tip: for **++** there is [`incrementProperty`](http://emberjs.com/guides/cookbook/working_with_objects/incrementing_or_decrementing_a_property/)

```
this.incrementProperty('frameIndex')

```

---

<div class="post-metadata">

**Author:** ![Laipak](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/laipak/32/9821_2.png) [@Laipak](https://discuss.emberjs.com/u/Laipak)\
**Post date:** [November 12, 2014, 8:21am UTC](https://discuss.emberjs.com/t/how-does-conditional-works/6674/5 "2014-11-12T08:21:50Z")

</div>

Is there any disadvantage using the native ++?

---

<div class="post-metadata">

**Author:** ![splattne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/splattne/32/3694_2.png) [@splattne](https://discuss.emberjs.com/u/splattne)\
**Post date:** [November 12, 2014, 2:09pm UTC](https://discuss.emberjs.com/t/how-does-conditional-works/6674/6 "2014-11-12T14:09:45Z")

</div>

You can’t use ++ on `.get('...')`
