utilizing angularjs and bootstrap to manage multiple button models

Recently delved into learning angularjs and bootstrap. Found a tutorial on creating buttons.

<div ng-controller="ButtonsCtrl">
    <h4>Checkbox</h4>
    <pre>{{checkModel}}</pre>
    <div>
        <button type="button" class="btn btn-primary" ng-click="checkModel.KateSpade = true" btn-checkbox>Kate Spade</label>
        <button type="button" class="btn btn-primary" ng-model="checkModel.LouisVuitton" btn-checkbox>Louis Vuitton</label>
        <button type="button" class="btn btn-primary" ng-model="checkModel.Burberry" btn-checkbox>Burberry</label>
        <button type="button" class="btn btn-primary" ng-model="checkModel.CalvinKlien" btn-checkbox>Calvin Klien</label>
        <button type="button" class="btn btn-primary" ng-model="checkModel.Forever21" btn-checkbox>Forever 21</label>
    </div>
</div>

Any tips on how to update the values of ng-model upon clicking? My controller setup seems pretty standard.

app.controller('ButtonsCtrl', function($scope){
    console.log("ButtonsCtrl has initiated");

    $scope.checkModel = {
        KateSpade: false,
        LouisVuitton: true,
        Burberry: false,
        CalvinKlien: false,
        Forever21: false
    };
});

Answer №1

It appears that the angular bootstrap UI website utilizes labels in their HTML structure. It seems like there are some errors in your code. You have an opening button tag and a closing label tag, which is not correct. Additionally, your first button uses ng-click instead of ng-model. Here is a corrected version of the HTML:

<div class="btn-group">
    <label class="btn btn-primary" ng-model="checkModel.KateSpade" btn-checkbox>Kate Spade</label>
    <label class="btn btn-primary" ng-model="checkModel.LouisVuitton" btn-checkbox>LouisVuitton</label>
    <label class="btn btn-primary" ng-model="checkModel.Burberry" btn-checkbox>Burberry</label>
    <label class="btn btn-primary" ng-model="checkModel.CalvinKlien" btn-checkbox>Calvin Klien</label>
    <label class="btn btn-primary" ng-model="checkModel.Forever21" btn-checkbox>Forever 21</label>
</div>

Don't forget to include and require the 'ui.bootstrap' module in your project. Check out this Fiddle link for more details.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the power of V-for with checkboxes in VueJS

One issue I am facing is related to triggering my save method only when a checkbox is selected or true in Vue JS. I have no problem listing values and saving them to the database using axios, Vue JS, and Spring Boot. However, every time I click the checkbo ...

Exploring AngularJS: A guide to extracting data from an image file

When attempting to send the image data to the back-end, I encountered an error while trying to read the image file: Uncaught TypeError: Failed to execute 'readAsArrayBuffer' on 'FileReader': parameter 1 is not of type 'Blob'. ...

Using Object Value as Variable instead of String in JavaScript/React

When working with React & JavaScript, I am storing an input name as a string in an object: window.ObjectOne = { ObjectOneKey: "MyInputName", } The input name can be an object path like "Object.FirstName" or a variable name "MyVariableName" What I am at ...

Exploring the JSON structure within MongoDB

I am looking to build a Json tree using data from 3 collections retrieved from MongoDB. For instance: Each area can have connections to other areas, spaces can be connected to areas and other spaces, and dashes are linked to spaces. What is the best app ...

What is the process for consumers to provide constructor parameters in Angular 2?

Is it possible to modify the field of a component instance? Let's consider an example in test.component.ts: @Component({ selector: 'test', }) export class TestComponent { @Input() temp; temp2; constructor(arg) { ...

Custom filtering in jqGrid with an integrated filtering toolbar

Hey there! I'm currently using the latest version of jqGrid and I was curious if it's possible to implement local filtering with custom rules. In the past, I had to manually add this feature because the version I was using didn't support it. ...

JSON conversion error: Unable to convert circular structure to JSON - locate problem within JSON structure

Currently, I am utilizing Contentful in conjunction with a MEAN stack. Upon querying the Contentful API, I receive a json object. contentClient.entries(query, function(err, entries){ if (err) throw err; console.log(entries); }); Lately, I have been e ...

The baffling quirks of variables within a Jquery loop

Unfortunately, I'm struggling to come up with a more fitting title for my question, but I'll do my best to provide a clear explanation of my issue. Here is the code snippet I am working with: let pdfInvoice_sub_template = [ {text: '{ ...

The audio must start playing prior to being forwarded to a new page

As I delve into the world of website development on my own, I have encountered an interesting challenge. At the top of my webpage, I have embedded an audio file within a button. If the user chooses to mute the audio, the navigation links will remain silent ...

Effortless JavaScript function for retrieving the chosen value from a dropdown menu/select element

I've figured out how to retrieve the value or text of a selected item in a dropdown menu: document.getElementById('selNames').options[document.getElementById('selNames').selectedIndex].value In order to simplify this code, I&apos ...

Transform Objects Array from AJAX Response into a Distinct JSON Entity

I am encountering a problem with a sample endpoint that is returning [object Object] for JSON data, and I can't figure out why. Mock API Initially, my code was a bit confusing, but fortunately, I found a clearer solution in another answer. functio ...

"An ng-repeat directive with a filter applied results in an empty

After successfully implementing the ng-repeat loop below: <div ng-repeat="einschItem in einschaetzungen.alldata | filter: { savedatum: lolatage[tagarrayindex].tagestring } | orderBy : '-savetimestamp'"> I wanted to check if the filtered r ...

Node.js - Retrieving POST request parameters and directing users in an Express application

I encountered this specific issue while setting up a post endpoint for my nodejs CLI script that utilizes express to handle requests. app.use( express.static( path.format({dir: __dirname, base: 'client/dist'})) ); app.use( express ...

JavaScript Subscribe / Unsubscribe Button

I am trying to create a simple JavaScript program that allows users to like and dislike content. However, I am new to JavaScript and finding it a bit challenging. Basically, when the user clicks on the Follow button, the "countF" variable should increase ...

Best Practices for Managing Data Across Multiple Locations in Angular.js

Currently, I am in the process of setting up a basic online shopping application using Angular.js. To display both an item list and item details, I utilize the ng-route module. For the item-list route, I employ resolve to load a JSON file containing vario ...

Displaying Dates in an Express Application using EJS

I have a MySQL table with a column containing date data. I am building a webpage to display this data in a more user-friendly way. Currently, the displayed result looks like this: I would like the dates in the column to be formatted as something like ...

Tips for determining what elements are being updated in terms of style

I need assistance with modifying the functionality of a webpage's dropdown menu. Currently, it displays when the mouse hovers over it, but I want to change it to appear on click using my own JavaScript. Despite setting the onmouseout and onmouseover e ...

Create a customized menu with jQuery that disappears when hovered over

Check out this menu I've created: http://jsbin.com/useqa4/3 The hover effect seems to be working fine, but I'm looking to hide the div #submenuSolutions when the user's cursor is not on the "Solution" item or the submenu. Is there a way to ...

Calculate the time difference in hours using time zone in Javascript

Within my JavaScript object, I have the following information: var dateobj = { date: "2020-12-21 03:31:06.000000", timezone: "Africa/Abidjan", timezone_type: 3 } var date = new Date(); var options = { timeZone: dateobj.timezone }; var curr_date ...

Is it possible to send a PHP variable to a popup using a button and JavaScript?

I am facing an issue with a dynamically created table in PHP that displays requests. Each row in the table has a button to open a popup. I need to pass the ID of each request to the popup to retrieve all the data associated with it. Can someone guide me o ...