How to feed images to Angular's UI Bootstrap Carousel

In my current project, I am incorporating the Angular UI Bootstrap carousel and want to customize it by using my own images. Below is the code snippet for the Carousel Controller that I have implemented:

.controller('CarouselCtrl', function ($scope) {
  $scope.myInterval = 2000;
  var slides = $scope.slides = [];
  $scope.addSlide = function() {
    var newWidth = 1 + slides.length + 1;
    slides.push({
      image: '../img' + newWidth,
      text: ['More','Extra','Lots of','Surplus'][slides.length % 4] + ' ' +
      ['Cats', 'Kittys', 'Felines', 'Cutes'][slides.length % 4]
    });
  };
  for (var i=0; i<4; i++) {
    $scope.addSlide();
  }
})

While I understand that the addSlide function populates an array with images and iterates over them, I am facing difficulties in changing the source path of the images to a folder within the project directory. Currently, the images are not being displayed as expected. The img folder is located one level above the .js file containing the Carousel Controller. Any guidance or suggestions on resolving this issue would be greatly appreciated. Thank you!

Answer №1

To ensure proper naming of the images, it is recommended to start with / (rather than ../) and keep in mind that this indicates the root web directory.

The accurate location would then be:

slides.push({
  image: '/pictures/pic' + newWidth,
  text: ['Additional','Extra','Abundant','Excess'][slides.length % 4] + ' ' +
    ['Dogs', 'Puppies', 'Canines', 'Adorable'][slides.length % 4]
});

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

Transforming an unconventional date format into a proper date representation

I have a spreadsheet with over 100,000 dates stored in the following format: Thursday 29th of October 2015 01:06:21 PM Converting these dates into a usable format is proving to be a challenge. Whether it's YYYY/MM/DD or any other standard format, I ...

using javascript to access an opened html div

I am making an AJAX request in A.html and once the response is successful, I want to display a message in B.html. (The message should be displayed in a div with the id='mes_div' which is located in B.html.) How can I access B.html and how do I ac ...

Is there a way to incorporate expandable content on a Drupal node page using Javascript?

Is there a Drupal Module available that can display a trimmed version of content on the node page and expand it when clicking on a "Read More" link? Thank you! ...

Can you explain the distinction between export/import and provide/inject in Vue3?

Can you explain the difference between export/import and provide/inject in Vue3? // parent const data = provide('data', ref(0)) // child const data = inject('data') // parent export const data = ref(0) // child import { data } from & ...

Using jQuery to manipulate XML: Altering XML content using its ID with jQuery

Trying to modify content within an XML using jQuery has been a bit tricky for me. Based on the examples I've found, I believe the code should look something like this: Javascript: get_verrichtingen: function(){ var self = this; var option = ...

What is the best practice for passing parameters to a child uiView in AngularJS?

I am working on a project with multiple states and views. angular.module('myapp', ['ui.router']).state('property', { url: '/property', views: { '': { templateUrl: 'partial/ ...

What methods can be utilized to accurately determine a user's online status without continuously sending AJAX requests to the server through setInterval?

Seeking effective methods to determine a user's online status I am currently employing an inefficient technique to address this issue: I continuously send AJAX requests to the server at set intervals using setInterval, allowing the server to gauge th ...

Setting a value programmatically in a Material-UI Autocomplete TextField

In my React application, I am using material-ui Autocomplete and TextField components to allow users to select values from a dropdown list. However, I am looking for a way to programmatically set the input value by clicking a button, without having to choo ...

Allow users to edit the textarea only to input values, not from

I am trying to achieve a specific functionality with two input fields and one textarea. Whenever I type something in the input fields, their values are automatically populated in the textarea using .val(). Currently, this feature is working as intended, b ...

What is causing the inability to successfully copy and paste Vega editor specs locally?

I successfully executed this spec in Vega Editor: { "$schema": "https://vega.github.io/schema/vega/v3.0.json", "width": 1, "height": 1, "padding": "auto", "data": [ { "name": "source", "values": [ {"name": "Moyenne","vo ...

Compatibility problem arising from the versions of ember-precompile, ember.js, and handlebars.js

Having trouble reading the precompiled templates in my HTML due to compatibility issues between ember-precompile, ember.js, and handlebars.js. My code looks like this: Includes the following files. <script src="../js/libs/jquery-1.10.2.js"></sc ...

angularDynamicLocation does not contain the specified localeLocationPattern

I am using angular-translate to handle localization with angular dynamic localization. I have attempted the following code, but for some reason the localization is not changing. I suspect that the issue lies in angular not being able to locate localeLocati ...

Using AngularJS with ngRepeat allows for the insertion of an extra element every specified number of repeats

I am attempting to establish a layout where every 7 repeated elements, an extra element is inserted. This additional element must be part of the parent container rather than being a child of one of the repeated elements. Simply changing the class is not s ...

What is the best way to indicate progress as the canvas resizes an image?

Is there a way for me to access progress updates? My main focus is on receiving progress information, regardless of how it will be displayed. I may choose to use a progress bar in the future, but my current inquiry pertains solely to obtaining the data it ...

Limiting Firebase queries with startAt and endAt

I need to retrieve the first 100 results from my Firebase data, followed by the next 100, and so on. Despite trying multiple methods, I have not been successful. Method 1 ref.child('products').orderByChild('domain').startAt(0).endAt(1 ...

The drag and drop feature seems to be malfunctioning in the Selenium Webdriver when using the Node.js (JavaScript) test automation framework

I am currently utilizing the selenium webdriver along with a customized automation framework built in nodejs. My goal is to implement drag and drop functionality for a slider using the actions class, but unfortunately I am encountering issues. Below you ca ...

Is there a way to automatically advance to the next question in Surveyjs without needing to click the Continue

I'm currently integrating SurveyJs into my web application. The first 3 pages of my survey contain HTML elements that I would like to automatically slide after a few seconds, similar to the functionality on the following sample site using SurveyJS: O ...

Ways to access a JavaScript object beyond the function scope

Using the code below, I am able to retrieve JSON data when an element is clicked. This data is then used to create a table, fill the cells with images, and append the table to a specific div. function LoadImagesByCategory() { $.getJSON("/Service/GetJs ...

Is there an effective way to merge two collections?

I came across an issue where I am attempting to merge two arrays that resemble the ones listed below: var participants = [ {id: 1, name: "abe"}, {id:2, name:"joe"} ]; var results = [ ...

"Utilize Cypress to simulate clicking a button by triggering the enter key

Currently, I'm conducting testing on my application and attempting to trigger a button click using the Enter key: <v-btn class="submit-button" block color="primary" @click="login" > Log In < ...