The Issue with AngularJS ng-repeat Function Not Functioning

I am attempting to utilize angularJS to display div cards in rows of 3, but it's not working as expected. Instead of showing the cards in rows, it's displaying pure HTML where the object keywords in {{ }} are appearing as plain text. Below is all the relevant code.

Index.html

<!DOCTYPE html>
<html>
  <head ng-app="inLineClient">
    <meta charset="utf-8>
    <title>Client App | InLine</title>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" href="/src/style.css">

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.7/angular.js"></script>
    <script src="./src/app.js"></script>
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

  </head>
  <body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
      <a class="navbar-brand" href="#">InLine</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarText">
        <span class="navbar-text">
          Welcome Back, User
        </span>
      </div>
    </nav>
    <div class="container">
      <div class="row">
        <h1 class="display-3">Current Conference: Conference</h1>
      </div>
      <div ng-controller="lineController as lineCtrl">
        <div class="row" ng-repeat="line in lineCtrl.linesList track by $index" ng-if="$index % 3 == 0">
            <div class="col-md-4" ng-repeat="i in [$index, $index + 1, $index + 2]" ng-if="lineCtrl.linesList[i] != null">
              <div class="card">
                <div class="card-header">
                  {{line.name}}
                </div>
                <div class="card-body">
                  <p class="card-text">{{line.description}}</p>
                  <ul class="list-group list-group-flush">
                    <li class="list-group-item">Time: {{line.time}}</li>
                    <li class="list-group-item">Number of People: {{line.numPeople}}</li>
                    <li class="list-group-item"><a href="#" class="card-link">Card link</a></li>
                  </ul>
                </div>
              </div>
            </div>
        </div>
      </div>
    </div>
  </body>
</html>

/src/app.js

angular.module('inLineClient', [])
.controller('lineController', function($scope) {
  $scope.linesList = [
    {
      name: 'Lunch',
      description: 'Lunch time! Come down for some pizza, french fries and drinks!\nPrice: $10 for Pizza, Fries, and a Soft Drink',
      time: new Date('October 21, 2017 12:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    },
    {
      name: 'VR Cave',
      description: 'Reserve your slot to play in our VR Cave',
      time: new Date('October 22, 2017 0:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    },
    {
      name: 'Breakfast',
      description: 'Good Morning! Bagels and Cream Cheese with Coffee, Tea and Hot Chocolate this morning!',
      time: new Date('October 22, 2017 8:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    },
    {
      name: 'Intro to RESTful APIs by RBC',
      description: 'Learn about how to create REST APIs for your web application, brought to you by RBC',
      time: new Date('October 21, 2017 17:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    },
    {
      name: 'Contest Programming',
      description: 'Get your programming on by competing among different hackers to win a prize!',
      time: new Date('October 22, 2017 0:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    }
  ];
});

If you have any suggestions or need further information, please leave a comment. Full repository available at https://github.com/khalid-talakshi/InLine

Answer №1

You have implemented $scope in your controller and are utilizing the Controller as syntax in your HTML.

To maintain consistency, choose one method to use. If you prefer to use the $scope variable, modify your HTML as follows:

<div ng-controller="lineController">
        <div class="row" ng-repeat="line in linesList track by $index" ng-if="$index % 3 == 0">
            <div class="col-md-4" ng-repeat="i in [$index, $index + 1, $index + 2]" ng-if="linesList[i] != null">
              <div class="card">
                <div class="card-header">
                  {{line.name}}
                </div>
                <div class="card-body">
                  <p class="card-text">{{line.description}}</p>
                  <ul class="list-group list-group-flush">
                    <li class="list-group-item">Time: {{line.time}}</li>
                    <li class="list-group-item">Number of People: {{line.numPeople}}</li>
                    <li class="list-group-item"><a href="#" class="card-link">Card link</a></li>
                  </ul>
                </div>
              </div>
            </div>
        </div>
      </div>

DEMO

// Your custom code

angular.module('inLineClient', [])
.controller('lineController', function($scope) {
$scope.message = "test";
  $scope.linesList = [
    {
      name: 'Lunch',
      description: 'Lunch time! Come down for some pizza, french fries and drinks!\nPrice: $10 for Pizza, Fries, and a Soft Drink',
      time: new Date('October 21, 2017 12:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    },
    {
      name: 'VR Cave',
      description: 'Reserve your slot to play in our VR Cave',
      time: new Date('October 22, 2017 0:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    },
    {
      name: 'Breakfast',
      description: 'Good Morning! Bagels and Cream Cheese with Coffee, Tea and Hot Chocolate this morning!',
      time: new Date('October 22, 2017 8:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    },
    {
      name: 'Intro to RESTful APIs by RBC',
      description: 'Learn about how to create REST APIs for your web application, brought to you by RBC',
      time: new Date('October 21, 2017 17:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    },
    {
      name: 'Contest Programming',
      description: 'Get your programming on by competing among different hackers to win a prize!',
      time: new Date('October 22, 2017 0:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    }
  ];
});
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>Client App | InLine</title>

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.7/angular.js"></script>
  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  <script src="script.js"></script>
</head>

<body  ng-app="inLineClient">
  <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <a class="navbar-brand" href="#">InLine</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarText">
      <span class="navbar-text">
          Welcome Back, User
        </span>
    </div>
  </nav>
  <div class="container">
    <div class="row">
      <h1 class="display-3">Current Conference: Conference</h1>
    </div>
    <div ng-controller="lineController">

      <div class="row" ng-repeat="line in linesList track by $index" ng-if="$index % 3 == 0">
        <div class="col-md-4" ng-repeat="i in [$index, $index + 1, $index + 2]" ng-if="linesList[i] != null">
          <div class="card">
            <div class="card-header">
              {{line.name}}
            </div>
            <div class="card-body">
              <p class="card-text">{{line.description}}</p>
              <ul class="list-group list-group-flush">
                <li class="list-group-item">Time: {{line.time}}</li>
                <li class="list-group-item">Number of People: {{line.numPeople}}</li>
                <li class="list-group-item"><a href="#" class="card-link">Card link</a></li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>

</html>

Answer №2

When utilizing the Controller AS approach, one must assign the 'this' keyword to another variable (in this case, 'vm') to access the controller properties using that variable as a reference. //index.html

    <!DOCTYPE html>
    <html>
      <head >
        <meta charset="utf-8">
        <title>Client App | InLine</title>

        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
        <link rel="stylesheet" href="/src/style.css">

        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.7/angular.js"></script>
        <script src="script.js"></script>
        <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

      </head>
      <body ng-app="inLineClient">
        <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
          <a class="navbar-brand" href="#">InLine</a>
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="navbarText">
            <span class="navbar-text">
              Welcome Back, User
            </span>
          </div>
        </nav>
        <div class="container">
          <div class="row">

            <h1 class="display-3">Current Conference: Conference</h1>
          </div>
          <div ng-controller="lineController as lineCtrl">
            {{lineCtrl.name}}
            <div class="row" ng-repeat="line in lineCtrl.linesList track by $index" ng-if="$index % 3 == 0">
                <div class="col-md-4" ng-repeat="i in [$index, $index + 1, $index + 2]" ng-if="lineCtrl.linesList[i] != null">
                  <div class="card">
                    <div class="card-header">
                      {{line.name}}
                    </div>
                    <div class="card-body">
                      <p class="card-text">{{line.description}}</p>
                      <ul class="list-group list-group-flush">
                        <li class="list-group-item">Time: {{line.time}}</li>
                        <li class="list-group-item">Number of People: {{line.numPeople}}</li>
                        <li class="list-group-item"><a href="#" class="card-link">Card link</a></li>
                      </ul>
                    </div>
                  </div>
                </div>
            </div>
          </div>
        </div>`enter code here`
      </body>
    </html>


//app.js

angular.module('inLineClient', [])
.controller('lineController', function($scope) {
  vm = this;
  vm.name = "arvind";
  vm.linesList = [
    {
      name: 'Lunch',
      description: 'Lunch time! Come down for some pizza, french fries and drinks!\nPrice: $10 for Pizza, Fries, and a Soft Drink',
      time: new Date('October 21, 2017 12:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    },
    {
      name: 'VR Cave',
      description: 'Reserve your slot to play in our VR Cave',
      time: new Date('October 22, 2017 0:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    },
    {
      name: 'Breakfast',
      description: 'Good Morning! Bagels and Cream Cheese with Coffee, Tea and Hot Chocolate this morning!',
      time: new Date('October 22, 2017 8:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    },
    {
      name: 'Intro to RESTful APIs by RBC',
      description: 'Learn about how to create REST APIs for your web application, brought to you by RBC',
      time: new Date('October 21, 2017 17:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    },
    {
      name: 'Contest Programming',
      description: 'Get your programming on by competing among different hackers to win a prize!',
      time: new Date('October 22, 2017 0:30 EST-05:00').toLocaleTimeString('en-US'),
      numPeople: null
    }
  ];
});

Check out the Plunker link here

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

Different ways to modify the underline and label color in Material-UI's <Select/> component

A while ago, I came across this useful demo that helped me change the colors of input fields. Here is the link: https://stackblitz.com/edit/material-ui-custom-outline-color Now, I'm on a quest to find a similar demo for customizing the color of selec ...

Executing multiple asynchronous XMLHttpRequests with React

I experimented with multiple asynchronous XMLHttpRequests based on various examples I came across: var URL=["https://api.github.com/users/github","https://api.github.com/users/github/repos"]; var xhr = [null, null]; for (var i = 0; i < 2; i++) { ( ...

"Utilize jQuery AJAX Promises to Trigger Custom Exceptions that can be Handled by the Outer fail() Function

Imagine having a function that yields a promise. The promise returned is scrutinized by other functions to determine how to manage the .fail() condition. function refreshTimeline() { var promise = ajaxMethod1() .then (function (data) ...

Eliminate the error notification on the login page if it corresponds to the input

I am facing an issue with my login page and the API for password validation. Even when the password matches, an error message is still being displayed. This is because I am looping through the data and need to break the loop once a match is found. How can ...

The function is not specified

Currently, I am in the process of implementing a login system using nodejs. My goal is to define a global function outside of a module and then call it multiple times within the module. However, I am encountering an issue where it always returns undefined, ...

Tips for adding up data tables in CodeIgniter

The output is displaying as $NaN ( $NaN total) I followed the code example from datatables and made modifications to the column for SUM function. Here is my code snippet: <script> $(document).ready(function() { $('#tableoperasional').Data ...

Exploring depths with nested ng-Repeat in Depth First Search

I am dealing with an object that has variable key names, each of which contains nested objects. My goal is to perform a depth-first search (DFS) over this object. For example, consider the following object: object = { "var1" : { "var2 ...

What is the best way to implement a required input field in Vue.js?

I need some assistance with my chat functionality. I want to prevent users from sending empty messages, so I want to make the input field required. Can you please help me with this? I have already tried adding "required='required'" to the input ...

Transforming the appearance of a compiled HTML component in AngularJS

UPDATING TEMPLATE VARIABLE ISSUE I have come across a problem where the value of the template variable is being lost. I'm not sure why this is happening yet, but I made some changes to the code: var template; $templateRequest("ng-templa ...

Ways to calculate the memory utilization of a JavaScript object

Suppose I want to compare the efficiency of storing bits of a static canvas/image with Alpha more or less than 0.5 using an "array of array of number" versus an "array of string," which would be better in terms of memory usage and speed? var c = $('m ...

Having trouble with sending POST data to server while trying to save to a JSON file using ajax and php

I attempted to follow the instructions from various stackoverflow posts, but it seems that my server is not acknowledging any incoming requests. I am certain that the client is sending the request because it can be seen in the Firefox debugger tool. Below ...

Can one access the method definition within a Visual Studio Code setup for an AngularJS project?

I'm on a quest to locate the method definition within my AngularJS project, but alas, I am struggling to discover a quick and easy shortcut for this task. My attempts with Ctrl + Click only led me to the initial occurrence of the variable's decla ...

Employing DOM manipulation within Vue unit tests as a last resort

What steps should I take to update my unit test in order to accurately validate the following scenario? Method: close(event) { const element = !!event?.target?.closest('#target') if (!element) { this.isVisible = false } }, Jest test: ...

Sign in a user post-registration with the help of AWS Amplify and React

After a user successfully signs up using the withAuthenticator component, they are immediately logged in upon email confirmation. Is there a way to automatically log them in using a custom sign-in process and the Auth object instead? If so, what steps wo ...

Gather and consolidate all files into a single file using Node.js / JavaScript

I currently have 3 JSON files located in my project/Folder file1.json { "id":"01", "name":"abc", "subject":[ "subject1":"Maths", "subject2":"Science" ...

Tips for inserting a property into an array of objects when it matches the specified ID

As someone new to Angular, I am encountering an issue and would appreciate some help. Here is an array of objects I am working with: signals = [{ 'signalID': '123' },{ 'signalID': '233' },{ 'signalID': &apo ...

How can I add text to a textbox within a duplicated div using Javascript or Jquery?

I'm looking to add text to a cloned div's text box using jQuery. I have a div with a button and text box, and by cloning it, I want to dynamically insert text into the new div. $(document).ready(function () { $("#click").click(function () { ...

The issue with the Sails.js application is that it fails to update files from assets after

Currently, I am working on a Sails.JS application with Angular.JS as its front-end framework. All the angular files are stored in /assets/linker and they are correctly injected upon start. However, I have encountered an issue where any changes made to the ...

Utilize the <a> element as a button to submit the data form

I am looking to transfer data from a form to another PHP page without using a button within the form itself. Instead, I have placed a separate button outside of the form for submission. How can I achieve this by sending the form data to the other page? Bel ...

The "ui.router" module is currently unavailable

Just starting out in AngularJS Encountered this error message: Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:modulerr] Failed to instantiate module ui.router due to: Error: [$injector:nomod] Module ' ...