AngularJS can be used to define Bootstrap columns in a unique and

My goal is to specify 4 different output layouts. In my HTML, I will define the number of columns to show, and then in JavaScript, execute the corresponding code based on the number of columns specified:

<div class="col-md-3">
    <h1>Content</h1>
</div>
<div class="col-md-3">
    <h1>Content</h1>
</div>
<div class="col-md-3">
    <h1>Content</h1>
</div>
<div class="col-md-3">
    <h1>Content</h1>
</div>

If there are 3 columns, this code should be executed:

<div class="col-md-4">
    <h1>Content</h1>
</div>
<div class="col-md-4">
    <h1>Content</h1>
</div>
<div class="col-md-4">
    <h1>Content</h1>
</div>

In case of 2 columns, use this code:

<div class="col-md-6">
    <h1>Content</h1>
</div>
<div class="col-md-6">
    <h1>Content</h1>
</div>

For a single column, run the following code:

<div class="col-md-12">
    <h1>Content</h1>
</div>

I am wondering if it's possible to achieve this using AngularJS.

Answer №1

Give this a shot:

New Code:

$scope.numbers = 3;//number of items 
$scope.getNum = function(number) {
    return new Array(number);
}

HTML:

<div ng-repeat="item in getNum(numbers) track by $index" class="col-md-{{12/numbers}}">
     <h2>New Content</h2>
</div>

http://jsfiddle.net/6tp9qyhf/1/

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

Using Template Literals to Log Arrays with Multiple Dimensions

Is there a way to use Template Literals to console.log() a multidimensional array without it being converted into a string? This example demonstrates the difference between logging an array with and without Template Literals: const multidimensionalArray ...

Issue with smooth scroll feature not functioning properly

Currently, I am facing an issue with the smooth scroll feature on my website. Although I have implemented a to top arrow for users to move back to the top section of the page, the scrolling is not as smooth as intended. The JavaScript code I used for achi ...

What is the technique for causing this element to move in reverse?

How can I utilize JS to halt the interval and direct the alien to move backwards once it reaches 700px? I am aware that CSS can achieve this, but I prefer a strictly JS approach. I am struggling with stopping the interval as it hits the left position of 70 ...

Rendering in React by cycling through an array and displaying the content

I have been working on displaying two arrays. Whenever the button is clicked, a new user is generated and added to the array. My goal is to render the entire array instead of just the newest entries. I've attempted various methods but haven't had ...

Exploring the capabilities of AngularJS's ui-router and ui-view features

I have my header stored in a header.html template file. I am attempting to incorporate it into my index.html using the following code: <div ui-view="header"></div> Even after implementing this, I still see a div surrounding my header tag. Is ...

How can I install fs and what exactly does it do in JavaScript?

As a beginner in the world of JavaScript, I am struggling with what seems like a basic issue. In my journey to develop some JavaScript code and utilize sql.js, I keep encountering an error at this line: var fs = require('fs'); This error is due ...

The blinking cursor in Google Docs is known as "kix-cursor-caret."

Although I adore Google Docs, I can't help but find the blinking cursor a bit too distracting for my liking. It seems that the latest version of Google Docs fails to comply with the operating system's setting for displaying a solid, non-blinking ...

What are the steps for integrating Socket.IO into NUXT 3?

I am in search of a solution to integrate Socket.IO with my Nuxt 3 application. My requirement is for the Nuxt app and the Socket.IO server to operate on the same port, and for the Socket.IO server to automatically initiate as soon as the Nuxt app is ready ...

Is there a way to selectively exclude default headers from certain XHR requests in AngularJS?

Most of my ajax requests require a specific "X-API-TOKEN" for authentication when interacting with my Rails REST API. However, I encountered an issue while making a call to a third-party API where the error message "Request header field X-API-TOKEN is not ...

What is the reason behind the controller being unable to locate an Angular model when it contains dots in its name?

I am completely new to Angular and struggling to comprehend this code snippet. app.controller('FileConfigController-detail', function($scope, $http, $stateParams, FileConfigDetailsService) { $scope.detail.inptITResourceID = "test me" ...

Angular 2 Web Workers HTTP Error: Promise Rejection - Not Supported

I've hit a roadblock with an error that I'm struggling to resolve. My Angular2 application operates entirely within a webworker, mostly following the guidelines outlined in this tutorial The first feature I implemented was using socket.io, which ...

What is the recommended sequence for adding AngularJS to the index page?

I am new to AngularJS and currently working on a project where I need to include multiple JavaScript files in my index.html page. After doing some research, I came across a post on Stack Overflow that mentioned the importance of including the angular.js fi ...

Bulma Steps failing to advance to the next step despite clicking submit

I am currently working on implementing Buefy Steps in a Vue project. The Buefy steps are functioning correctly, but I am facing an issue where the 'Submit' button does not progress to the next step (e.g., from "Account" to "Profile"). App.vue: & ...

I can't seem to get my table to show up when I try to display it using 'onload'. What could be the issue

There's a strange issue going on - when I use document.write() outside of the window.onload = function(){}, it works perfectly. However, if I try to call it from inside, nothing happens. Even though I can see that the table is being created (I checked ...

Does an async function get automatically awaited if called in a constructor?

I am currently working on updating some code due to a library upgrade that requires it to be made async. The code in question has a base class that is inherited by other classes, and I need to call some functions in the constructor that are now asynchronou ...

Tips on utilizing the b-pagination API?

layoutchange() { this.layout = !this.layout; if (this.layout === true) { this.perPage = this.layout ? 8 : 12; this.listProducts(); } else { this.perPage = !this.layout ? 12 : 8; this.gridProducts(); } }, <a class="list-icon" ...

Transmitting data from a form to PHP script with AJAX

I've been attempting to figure this out for several hours now, and I'm running out of ideas. I've browsed through numerous questions on this topic, but they seem too complex or confusing for me as my exposure to javascript/jquery is fairly r ...

Is there a solution for passing multiseries data in JSON that works with AnyChart in ReactJS since the standard method is not functioning correctly?

I need help implementing a column chart using AnyChart in react with multi-series data. Below is a sample JSON structure that I am having trouble passing to the chart. const multiSeriesSettings = { width: 800, height: 600, type: "column", ...

Event triggered when a text input field becomes active (excluding onfocus) in the FireFox browser

I'm currently working on detecting when a text input field is active. Initially, I used the onfocus event, but I encountered an issue where the onblur event would be triggered when the window was no longer in focus, causing unintended consequences in ...

Understanding image sizes for uploads on Tumblr can be a bit confusing, especially when comparing pages to posts. Learn how to implement lazyloading for post

I'm currently working on a highly customized Tumblr account that features a mix of pages and posts. I am looking to access content and assets, particularly images, from these pages/posts for use in other parts of the site. When I upload an image to a ...