Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to make a toggle button in Angularjs

$scope.toggleButton = { inAddState: true };
$scope.update = (id, button) => {
    if (button.inAddState) {
        // logic to add
    } else {
        // logic to remove
    }
    // make sure you switch the state of the button at some point
    button.inAddState = !button.inAddState;
}

<button ng-click="update(data.id, toggleButton)" 
        class="btn {{ toggleButton.inAddState ? 'btn-primary' : 'btn-warning' }}"
        ng-bind="toggleButton.inAddState ? 'Add' : 'Remove'">
</button>
Comment

PREVIOUS NEXT
Code Example
Javascript :: destructuring js 
Javascript :: fibonacci series javascript using recursion explanation 
Javascript :: post requests javascript 
Javascript :: js quote 
Javascript :: how to make callback function javascript 
Javascript :: for pug 
Javascript :: push an item to array javascript 
Javascript :: javascript return function 
Javascript :: JavaScript and HTML DOM Reference 
Javascript :: js object delete value by key 
Javascript :: break loop if condition is met 
Javascript :: object constructor js 
Javascript :: alert modal 
Javascript :: object 
Javascript :: while loop javascript 
Javascript :: how to make an if statement in javascript 
Javascript :: rename files in folder 
Javascript :: aws lambda function setup for node js 
Javascript :: search in array javascript 
Javascript :: filter table search 
Javascript :: clone an object javascript 
Javascript :: array of objects in js 
Javascript :: how to sort an array 
Javascript :: how to query array of object in mongoos 
Javascript :: object destruction in javascript 
Javascript :: map function 
Javascript :: jfif to jpeg javascript 
Javascript :: foreach function into arrow with addeventlistener 
Javascript :: js.l6 
Javascript :: play mp4 vue js 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =