Why Angular ng-repeat does not bind or display any values in Twig template

I am encountering difficulties while starting my new Angular project. Initially, I have a controller named DashCtrl in a module called sandpiper, with plans to divide it into services later on.

The goal is to create a list of div.card elements from the $scope.results array within DashCtrl. Furthermore, clicking the add-button should append additional items to $scope.results and display $scope.test in the header. However, after clicking the button multiple times, an unexpected outcome occurs (view screenshot here)

Although $scope.pushit() successfully functions and ng-repeat displays the correct number of items, the titles are missing. Additionally, $scope.test does not appear as expected. Despite spending several hours troubleshooting and even creating a basic Angular test on JSFiddle, I am unable to resolve this issue.


Below is my JavaScript code (two scripts, minified into /build/sandpiper.min.js later)

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

app.controller('DashCtrl',['$scope',function($scope){

    $scope.test = "Header"

    $scope.results = [
        {
            title: "Test Item 1",
            file: "12345978-My-Test-Document.pdf",
            type: "PDF",
            tags: ['pdf','test','foo','bar'],
            image: "static/img/pdf.png"
        }
    ]

    $scope.pushit = function(){
        $scope.results.push({
            title: "Test Item 1",
            file: "12345978-My-Test-Document.pdf",
            type: "PDF",
            tags: ['pdf','test','foo','bar'],
            image: "static/img/pdf.png"
        })
    }
}])

And here's my HTML code snippet (unrelated parts excluded)

<!DOCTYPE html>
<html lang="en">
<head>

(...)

    <!-- bower:js -->
    <script src="../bower_components/jquery/dist/jquery.js"></script>
    <script src="../bower_components/materialize/bin/materialize.js"></script>
    <script src="../bower_components/angular/angular.js"></script>
    <!-- endbower -->

    <script src="/build/sandpiper.min.js"></script>
</head>
<body ng-app="sandpiper">
    <main>
        <div class="container" id="content-root">
            <div id="dash-wrapper" ng-controller="DashCtrl">
                <h3>Test {{ test }}</h3>
                <a ng-click="pushit()" class="btn-floating btn-large waves-effect waves-light" id="add-button">
                    <i class="material-icons">add</i>
                </a>
                <nav>
                    (...)
                </nav>

                <div class="row" id="results-container">
                    <div class="col s12 m4 l3" ng-repeat="item in results">
                        <div class="card">
                            <div class="card-content">
                                <span class="black-text">{{ item.title }}</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>

    (...)
</body>
</html>

I would greatly appreciate any assistance. Thank you in advance for your help. Hopefully, it's not a simple mistake...

(As this is my first post here, please let me know if I'm making any errors)

Answer №1

After some investigation, I finally found the root of the problem. It turns out that the issue was not with my CSS includes (I'm using Materialize) as I initially thought, but rather with Twig, a PHP template engine that also utilizes mustache notation for variables. The backend system was stripping away my bindings before they could even make it to the browser. It's amazing how such a small oversight caused so much trouble.

If you're facing a similar dilemma, consider changing the Angular delimiter or experimenting with a different tag_variable pattern for Twig.

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

Decoding the build ID in NextJS: A step-by-step guide

When working with NextJS, there's the option to generate a build ID as mentioned in the documentation here: https://nextjs.org/docs/app/api-reference/next-config-js/generateBuildId Alternatively, it is also possible to retrieve the build ID based on ...

When the window is loaded, a function is triggered

I attempted to create a function that generates a canvas with customizable width and height parameters. When I tried to call the function with createCanvas(200, 200) in another file, an error appeared on the console: Uncaught ReferenceError: createCan ...

Sending a Javascript string to PHP

I am trying to send a JavaScript string to PHP immediately after the code within the script tag. <script type="text/javascript"> var myvar = "mytext" ; <?php echo myvar ; ?> </script> Unfortunately, this approach is not functioning ...

Problem with the "md-open-on-focus" behavior in the Angular-Material's "md-datepicker" directive

When testing the functionality of the fiddle, an inconsistency issue was observed with multiple openings of the md-datepicker while using md-open-on-focus. The problem arises after the first successful opening and closing - subsequent attempts to open it ...

Sending a JSON object from JSP to JavaScript using AJAX

Is there a way to transfer JSON values from JSP to JavaScript as an object using AJAX without resorting to global JavaScript variables, which can expose the JSON content in the page's source? The desired scenario is as follows: The JSP URL is opene ...

Creating a precise regular expression for route length in Express JS

Currently, I am facing an issue while setting a route in my application. I want the URL parameter to be exactly 2 characters long, but unfortunately, the following code snippet is not producing the desired result: app.all('/:lng{2}?',function (r ...

Issue with Unslider functionality when using navigation buttons

I've implemented the OpenSource "unslider" to create sliding images with navigation buttons, but I'm facing an issue with the code provided on http:www.unslider.com regarding "Adding previous/next lines." Here are the CSS rules and HTML tags I h ...

Is it possible to load the response from the $.post function, which contains GIF content, into a JavaScript Image object

How can I preload an image that the server only returns on a POST request? I want to load the image before displaying it. How can I store the result in a JavaScript object? $.post('image.php', {params: complexParamsObject}, function(result) { ...

Preventing PCs from accessing a specific webpage: A step-by-step guide

I am currently using the code below to block phones: if { /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini/i .test(navigator.userAgent)) { window.location = "www.zentriamc.com/teachers/error ...

Error Alert: jQuery AJAX Event is not defined in Firefox Browser

This snippet works perfectly on Webkit browsers, but for some reason, it's not functioning in Firefox. I have a feeling that I need to include "event" within parentheses somewhere, but I'm unsure about the correct placement. Any ideas? html < ...

What is the process for inserting additional information into a geoJson file?

In the "gj" object, I need to add new properties from the "dataToAdd" array. The current format of "gj" is as follows: const gj = { "type": "FeatureCollection", "features" : [ { "type": "Feature", "geometry": { ...

Integrating jQuery class into code snippets

I have implemented a fixed header on scroll by adding the class 'fixed' and it is working fine. When I scroll down, after 50px, the 'fixed' class is added to my header container. However, when I scroll back up, the 'fixed' cla ...

The mistake occurs when attempting to access a class property generated by a class constructor, resulting in a type error due to reading properties of

I'm having trouble building an Express API in TypeScript using Node.js. I am new to Express and I have been learning Node, JavaScript, and TypeScript since 2022, so I apologize if the question is not too complex. The issue I'm facing is trying to ...

The TypeScript compiler generates a blank JavaScript file within the WebStorm IDE

My introduction to TypeScript was an interesting experience. I decided to convert a simple JavaScript application, consisting of two files, into TypeScript. The first file, accounts.ts, contains the main code, while the second one, fiat.ts, is a support f ...

Reinvent the AJAX functionality

Is there a way to create a custom function that changes the default ajax functionality? I currently have this ajax function implemented: $.ajax({ type: "POST", url: "http://" + document.location.host + '/userajax', data: 'type= ...

Is there a way to create tabs in JavaScript without having to edit the <head> section?

I am in need of JavaScript for creating tabs without the necessity of editing the <head> (as it is not possible). My requirement involves having three links and three divs. Whenever a link is clicked, one specific div should be displayed while the o ...

Unable to utilize query parameters with an ExpressJS API on localhost

Within my index.js file app.use('/api/v1/users', userRouter) In the Router file router.get("/:id", getUserDataById); When using Postman: The GET URL I am using is: http://localhost:3000/api/v1/users?id=120622 The error message is: C ...

I am encountering some difficulties with the functionality of the angularjs dialog

I've been attempting to integrate an AngularJS dialog feature into my application by following the examples provided on material.angularjs.org. However, despite copying everything accurately, I am unable to get it to function. Can anyone help identify ...

Error not identified in ajax function for form submission

For some reason, in IE8 specifically, the alert function is not firing and the ajax part of my code is not running when I try to submit a form. Even though I have included a return false, the form still gets submitted. Why is this issue only occurring in ...

Activate collapsible navigation icon when clicked on a smaller screen

Seeking assistance as a newcomer to coding. Struggling to implement a responsive navbar icon that changes on small screens when clicked. Utilized a bootstrap navbar but encountering issues where clicking the navbar on a small screen only displays the list ...