Adjust the color scheme of the active button in angularjs to create a fresh new

Here is the code snippet I am using to highlight the color of the currently active page button:

<li ng-repeat="pageNumber in pages track by tracker(pageNumber, $index)" 
    ng-class="{active :pagination.current == pageNumber, disabled : pageNumber == '...' }">
        <a href="" ng-click="setCurrent(pageNumber)">{{ pageNumber }}</a>
</li>

Take a look at the button image provided here:

https://i.sstatic.net/X2gYO.jpg

I want to customize the color of the active button. Can anyone help me with this?

Answer №1

Using ng-class allows you to assign a specific CSS class based on an expression. In this situation, the active style is applied when it is the current page.

You will need to find the definition of the active style in your CSS files to determine the color associated with it.

Answer №2

You are encountering a Syntax Error, please refer to the code snippet below for correction:

<li ng-repeat="pageNumber in pages track by tracker(pageNumber, $index)"  ng-class="{'active' :pagination.current == pageNumber, 'disabled' : pageNumber == '...' }">
    <a href="" ng-click="setCurrent(pageNumber)">{{ pageNumber }}</a>
</li>

Make sure to also update your CSS with the following:

.active{
    background-color:#000; // Enter your color Code or name
}

Answer №3

There seems to be a syntax error in your code. Here is a corrected version:

  ng-class="{'active' :pagination.current == pageNumber}"

var myApp = angular.module('myApp', []);

myApp.controller('MyController', function MyController($scope) {
  
  $scope.pagination = {
      current: 2
    };

  $scope.pages = [1,2,3,4,5,6,7];
  
  $scope.setCurrent = function(pageNumber){
       $scope.pagination.current = pageNumber;
 
    }
  
});
.active{
    background-color:green;
  }
li {
    display: inline-block;
}

li > a{
    color: red;
    text-decoration: none;
    padding: 3px 8px;
}

li > a:hover{
    background-color: black;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.12.0/moment.js"></script>

<div ng-app="myApp" ng-controller="MyController">
     <li ng-repeat="pageNumber in pages"  ng-class="{'active' :pagination.current == pageNumber }">
        <a href="" ng-click="setCurrent(pageNumber)">{{ pageNumber }}</a>
    </li>
</div>

Answer №4

Make sure to include the active class within single quotes

angApp = angular.module('myApp', []);

angApp.controller('MyController', function MyController($scope) {

  $scope.pagination = { current: 2 };

  $scope.pages = [1,2,3,4,5];
  console.log($scope.pages);
  
});
li {
    display: inline-block;
    padding:5px 10px;
    border: 1px solid #ccc;
    margin-right:5px;
    
}

li>a{
    color:black;
}

.active-button{
  background-color:green;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="myApp" ng-controller="MyController">
     <li ng-repeat="pageNumber in pages"  ng-class="'active-button' :pagination.current == pageNumber " ng-click="pagination.current = pageNumber">
        <a href="" >{{ pageNumber }}</a>
    </li>
</div>

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

Ways to prevent users from being redirected when they press the back button on a webpage

Similar Question: How can I prevent the back button from working in IE and Firefox? I'm currently working on a single page website (DAM) that requires user authentication to enter. After logging in, if a user clicks the back button, they are dire ...

Concealing the nearest object

I am currently working on using jquery to hide certain content on a website's index page. Within the fiddle, there is commented out code which I have been experimenting with - however, it hides all content divs if any toggle link is clicked. HTML & ...

Repurposing JavaScript objects after clearing their contents

Here's my issue. I'm working with a Javascript object, initialized as var stack = {}. This object is used in my project to store arrays. When the user clicks the add button, an array is added to the object with a specific key that is inputted in ...

Discovering all input elements by utilizing nextAll in jQuery

Here is the HTML structure: <div class="field phone"> <input type="text" maxlength="3" /> </div> <div class="field phone number1"> <input type="text" maxlength="3" /> & ...

Navigating and retrieving information from JSON data

I'm working with JSON data that I have received: [{"pk": 7, "model": "pycourt_login.orders", "fields": {"status": 0, "delivered": false, "order_id": "6count1%2", "student_id": 5, "counterid": "counter1", "datetime": "2011-04-05 01:44:01", "dish": 6, ...

I seem to be having an issue here - my style sheet just won't load

I am having an issue with my external style sheet named style.css. style.css #topbar { background-color: red; width: 1000px; height: 40px; } body{ background-color: green; } I have tried calling this style.css from the root folder, but it's not ...

Issues with Semantic UI Calendar not displaying properly

I am currently experimenting with the Semantic UI Calendar, where there is a date input field and a calendar that pops up when selected as demonstrated in this initial example. Since I am not familiar with this process, I am uncertain if I have properly li ...

JavaScript AJAX Event Listener

Currently seeking a way to intercept ajax events in JavaScript before any Ajax method is triggered. While there is an ajaxListener in JQuery that could work if all the ajax requests were from JQuery, unfortunately, they are not. So the question remains: ho ...

What could be the reason for the full name not being updated in the model when the last name is changed

Can you explain why the full name in the model does not update when I change the last name? You can view the code on Plunker: http://plnkr.co/edit/cqmwJc5dpoDWvai4xeNX?p=preview var loginCntrl=function($scope){ $scope.testClick =function(){ $scope. ...

Implementing a Preloader in a React Web App

I am looking to implement a preloader in my React application because it takes a long time to load. I want the preloader to automatically render until all the contents of my application are fully ready to be loaded. Is it possible to achieve this? I could ...

What is the best way to retrieve a value from a button function in order to utilize it in AJAX requests and SQL queries?

Having an edit button that allows users to change category names. When the edit button is clicked, a pop-up alert appears with an input field. Users can type in the input field, press okay, and the value should update with the input. This is the current co ...

Is the order of SCSS (SASS) selectors important when dealing with nested classes?

Exploring SCSS Styles for List Items In this code snippet, I am investigating the order of selection for classes and pseudo-selectors in SCSS. Specifically, I am questioning whether &:before.active is equivalent to &.active:before. Here is an exa ...

Adding an external JavaScript file to an Angular 5.0.0 project

Struggling to integrate hello.js into my Angular 5.0.2 project. See the CLI version below https://i.sstatic.net/RcGz5.jpg I have included the script file in angular-cli.json. "scripts": [ "./js/hello.js", "./js/hello.polyfill.js", ...

Tips for identifying changes in APIs during the simulation of end-to-end tests?

I am seeking to establish a strong e2e testing framework for our team's project, but I am struggling to find a straightforward solution to the following question: When all calls are mocked, how can we effectively detect if the actual model of the obj ...

Accessing the page directly in a Nuxt SPA is not permitted

I'm currently working with Nuxt version 2.3.4. In my project, I am utilizing vue-apollo to fetch data for a file named pages/_.vue, which dynamically manages content. As indicated on this documentation page, this is the recommended approach for handli ...

A mysterious underscore suddenly materializes within Font Awesome icons when used in HTML

Currently, I'm working on the footer section of a webpage using HTML and Bootstrap 5.3.0. I encountered an issue where an underscore appears next to the icons when I add them. I suspect that this is due to the white spaces between the elements, which ...

Utilizing the .map() function to display both the property value and property name of a JavaScript object

Essentially, my goal is to output an object within a react component. Here is an example of what the object looks like: var obj = { prop1: "prop1", prop2: "prop2", prop3: "prop3", } I want to display both the property name and its value, and I am ...

Modifying the class when ng-focus is triggered in AngularJS

Here is the HTML code that I am working with: <div class="icon fluid select" ng-init="focused = false"> <i ng-class="{'large svg guests icon':rooms==2, 'large svg guest icon':rooms==1,'active':focused==true}"> ...

Issue with displaying Wavesurfer.js waveform in custom Shopify section

Greetings to the Stockoverflow Community, I am facing a challenge with integrating WaveSurfer.js into a customized section on my Shopify store. Even though I have successfully implemented the section, the waveform visualization is not appearing. Link to ...

Instructions for separating a string into smaller parts, further splitting one of the resulting parts along with another associated value, and then combining the leftover segments with the remaining parts

My goal is to work with a string that is between 2000 and 3000 characters long, containing over a hundred non-uniformly placed \n characters. I want to divide this string into segments of 1000 characters each. In the resulting array of strings, I want ...