Skip to content

Instantly share code, notes, and snippets.

@bsylvain
Last active April 19, 2018 13:02
Show Gist options
  • Save bsylvain/9487b0851da494e67faf5db5021ab6a6 to your computer and use it in GitHub Desktop.
Save bsylvain/9487b0851da494e67faf5db5021ab6a6 to your computer and use it in GitHub Desktop.
Button triggering an API call than can fail or succeed
{{the-button isFailure=isFailure isSuccess=isSuccess onCLick=somethingToDo buttonLabel='Do Something'}}
import Ember from 'ember'
export default Ember.Controller.extend({
isFailure: false,
isSuccess: false,
actions: {
somethingToDo(){
something.do().then(()=>{
this.set('isFailure',false);
this.set('isSuccess',true);
},()=>{
this.set('isFailure',true);
this.set('isSuccess',false);
}
);
}
}
});
<button type="submit" class="btn btn-primary btn-xs" {{action "onClick"}}>
{{buttonLabel}}
{{#if isFailure}}
<i class="fa fa-ban text-danger"></i>
{{/if}}
{{#if isSuccess}}
<i class="fa fa-check"></i>
{{/if}}
</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment