Looking for help with Angular JS!

Hi there, I'm a new member on Stack Overflow and I have this snippet of code:

<div class="col-sm-9" ng-controller="BlogController as blg" ng-repeat.start="detail in blg.details">
  <h4><small>RECENT POSTS</small></h4>
  <hr>
  <h2>I Love Food</h2>
  <h5><span class="glyphicon glyphicon-time"></span> Post by Jane Dane, Sep 27, 2015.</h5>
  <h5><span class="label label-danger">Food</span> <span class="label label-primary">Ipsum</span></h5><br>

I'm interested in utilizing ng-repeat to organize these titles and elements in a separate JS file. Can anyone provide guidance on how to achieve this? Thank you!

Answer №1

Check out this solution that might help you with your problem.

An Angular application along with a controller is provided below:

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

myApp.controller('BlogController',function(){
this.details = [
                 {title: 'I Love Food',
                  author: 'Jane Dane',
                  date: 'Sep 27, 2015',
                  categories: [{name:'Food', class: ' label-danger'}, {name:'Ipsum', class: ' label-primary'}],
                  content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'
                 },
                 {title: 'I Love World',
                  author: 'Jane Dane',
                  date: 'Nov 12, 2015',
                  categories: [{name:'Nature', class: ' label-warning'}, {name:'Ipsum', class: ' label-primary'}],
                  content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'
                   }
                 ]
});

Here's the corresponding HTML code:

<body ng-app="myApp">
  <div class="col-sm-9" ng-controller="BlogController as blg">
    <h4>
      <small>RECENT POSTS</small>
    </h4>
    <hr />
    <div  ng-repeat="detail in blg.details">
      <h2>{{detail.title}}</h2>
      <p>{{detail.content}}</p>
      <h5>
        <span class="glyphicon glyphicon-time"></span>
        Post by {{detail.author}}, {{detail.date}}.
      </h5>
      <h5>
        <span ng-repeat="category in detail.categories" class="label {{category.class}}">{{category.name}}</span>
      </h5>
      <br />
    </div>
  </div>

</body>

Visual representation of the solution can be seen here.

You can view the full solution on Plunker.

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

How can I transfer an array of objects obtained from an ajax call to an observable array?

One of my functions involves making an ajax call and receiving data in the callback. It looks something like this: function fetchData(callback) { //perform ajax if(callback) { callback(data.data); } } If I use the function like this: fetc ...

What is preventing me from receiving the value from the Ajax call?

I have developed an Ajax function that looks like this: function searchPlanAjax(url){ jQuery('#loader').css('display','block'); var plan = jQuery('.rad').val(); var site = url+"fbilling_det ...

Display the files contained within a folder on the right side of a container by utilizing vue.js

I am currently working on an application that involves a list of folders, each containing various files. The goal is to display these files when a specific folder is chosen. On the left side, users will see a list of folders and on the right side, the resp ...

The addEventListener feature in Bootstrap 5.2.3 seems to be malfunctioning

I have a sample page with a Bootstrap dialog being returned from the server. I want to display it inside a DIV. However, when clicked, I receive this error: Uncaught TypeError: myModal.addEventListener is not a function It points to this line of code: ...

Error encountered in Angular/Karma/Jasmine: Trying to access a property or method (commLogger.SetLogLevel) on an undefined object

I'm currently learning about Karma and Jasmine Unit Testing, but I've run into an error that I can't seem to find a solution for on this site or anywhere else. Below is the code snippet from my unit test file: describe('CommLogger&apo ...

Emphasize a specific word within a table row using Reactjs

There is a row object called 'user' that contains key-value pairs of columns and their values. My goal is to highlight all occurrences of a specific word in that row and then return the updated row within a ReactJS table. I attempted the followi ...

What steps are needed to programmatically set the default page for Chrome and Firefox browsers?

Is there a way to use a native client (written in C++) to programmatically set the home page for both Chrome and Firefox browsers on a machine? I am trying to set the home page for all installed browsers to a specific URL. ...

When the page height is altered in real-time, it prompts a scroll event

When a slider on the page automatically switches slides and changes its height, it causes a scroll event to trigger unexpectedly. I want to modify the scroll event so that it only activates when the user physically interacts with the page by scrolling, r ...

Troubleshooting Next.js 14.1 Pre-rendering Issue: A Step-by-Step Guide

I just updated my Next.js from version 14.01 to 14.1 and encountered an error during the build process of my application. How can I resolve this issue? The error message reads as follows: Error occurred while prerendering page "/collections". For more inf ...

What is the best way to simulate the axios call within my express controller?

My axios call is already separated into a module and tested using mocked axios. However, I am facing a dilemma when it comes to testing the controller that imports this function. I understand that it needs to be mocked, but I am uncertain about the most ef ...

When using the setTimeout function, jQuery's .submit() method may fail to pass data to PHP

I'm attempting to enhance the login form with an effect that triggers a 1-second delay before proceeding to PHP. I tried implementing a setTimeout() function within the .submit event handler along with e.preventDefault() to create the delay, but enco ...

Move the camera in Three.js along a path between two vectors

I created a basic scene and came across a tutorial at to help me move the camera: var timer = new Date().getTime() * 0.0005; camera.position.x = Math.floor(Math.cos( timer ) * 200); camera.position.z = Math.floor(Math.sin( timer ) * 200); However, I n ...

Toggle React like button

I am working on a component that displays the number of likes next to a 'like' button. I want to implement a functionality where clicking the button once adds to the number of likes, but if clicked again, it reverts back to the previous state. Th ...

Is it possible to dynamically close the parent modal based on input from the child component?

As I follow a tutorial, I am working on importing the stripe function from two js files. The goal is to display my stripe payment in a modal. However, I am unsure how to close the modal once I receive a successful payment message in the child. Below are s ...

Is there a way to create a discord.js bot that can search for past messages without the need for a json file or storing them in a database?

Similar to the search feature in Discord. Imagine being able to enter !search [user] [query] and getting a response like "50 messages match your query." This would be like a word counting bot that doesn't need a database or local storage.The bot ...

Unable to retrieve the size of the dynamically generated array within the ngOnInit() lifecycle hook in Angular

Recently, I encountered an issue where I couldn't retrieve the length of a dynamically generated array in my Angular application's ngOnInit() method. @Component({ selector: 'rise-our-champions', templateUrl: './our-champions.c ...

Loading Images Dynamically in React with JSON Fetching

Here's the issue I'm facing: Below is a JSON object containing information about images: const imagesData = [ { "imagepath": "./images/a.jpg", "title": "Red Car", "uploadDate": "2 May 2020", "index": "0" } ...

What is the best way to implement an ng-change function on multiple fields within the same page without causing a cyclic call loop?

In my page, I have three angular-moment-datepicker fields - a date picker field, a month picker field, and a year picker field respectively. Here is the code: <input class="form-control" placeholder="BY DAY" ng-model="date" moment-picker="gDate" start- ...

Ways to resolve incorrect URL that interfere with date search results

I'm currently developing a webpage that displays user data in a table using bootstrap and PHP Laravel. It features search functions by date and name, a form control for selecting the number of entries per page, pagination buttons, and other miscellane ...

Pull data from another domain's DIV using jQuery's load/ajax function

I need to load content from a different domain into a DIV on my JSP page. For example: $("#myDiv").load("https://www.google.com") The issue I'm facing is that the request is being blocked by the browser's same origin policy. I've explore ...