0

I’ve been having a problem with a scope property in my controller – a simple test title and an array of strings used with ng repeat. They are not being displayed on the screen when served up from our rather complex server. Note that with ng repeat it seems to know the size of the array, just doesn’t display it, see first example below.

They are being displayed correctly when served up from apps like codepen or plunker. It also works when I run it on localhost using a simple server. See working version in 2nd example below.

I know responders will protest that they cannot help without more specific information about our server - but I'm guess I'm asking specifically:

  1. Have you seen a case where ng repeat seems to know the size of the array, but just doesn’t display the items in the array - if so what caused it?

  2. What types of issues with our server do you think could cause this? What should I be looking for..

    Non working example from our server

Working example from codepen or simple server on localhost

var app = angular.module('testApp', []);
angular.module('testApp').controller('AuthorizePageCtrl', ['$scope', function ($scope) {

    'use strict';

    $scope.mytesttitle = "this is a test";

    $scope.myitems = [
        "Alfreds Futterkiste",
        "Berglunds snabbköp",
        "Centro_comercial Moctezuma"
    ];

}]);
<!DOCTYPE html>
<html data-ng-app="testApp">

<head>
    <meta charset="utf-8" />
    <script data-require="[email protected]" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js" data-semver="1.5.8"></script>
    <script src="/js/controllers/AuthorizePageCtrl.js"></script>
</head>

<body>

<div id="consent" ng-app="testApp">

    <div ng-controller="AuthorizePageCtrl">
        <h3>My test title should appear->{{mytesttitle}}</h3>

        <div>
            <ul>
                <li ng-repeat="myitem in myitems">"myitem in myitems should appear->"{{myitem}}</li>
            </ul>
        </div>

        <div  ng-repeat="myitem in myitems">
            <h2>"myitem in myitems should appear->"{{myitem}}</h2>
        </div>
    </div>
</div>

</body>

</html>

3
  • Any console errors while running on the server ?? Commented Nov 6, 2017 at 6:37
  • What happens if you do something like <span ng-bind="myitem"></span instead of {{myitem}} ? Also, what do you see when you inspect the markup? Commented Nov 6, 2017 at 7:02
  • Hmm that's really odd did you check the callback function if it got the data ? Commented Nov 6, 2017 at 7:11

2 Answers 2

1

so first data-ng-app and ng-app they are the same. and you only need one. and for the JS i may this changes and it works for me.

Angular part:

var app = angular.module('app', []);
app.controller('AuthorizePageCtrl', ['$scope', function ($scope) {

$scope.mytesttitle = "this is a test";

$scope.myitems = [
"Alfreds Futterkiste",
"Berglunds snabbköp",
"Centro_comercial Moctezuma"
];
}]);

HTML part:

<!DOCTYPE html>
<html ng-app="app">

<head>
<meta charset="utf-8" />
<script  src="//code.angularjs.org/1.6.6/angular.js" ></script>
<script  src="app.js" ></script>
</head>

<body>

<div id="consent" >

<div ng-controller="AuthorizePageCtrl">
<h3>My test title should appear->{{mytesttitle}}</h3>

    <div>
        <ul>
            <li ng-repeat="myitem in myitems">"myitem in myitems 
 should appear->"{{myitem}}</li>
        </ul>
    </div>

    <div  ng-repeat="myitem in myitems">
        <h2>"myitem in myitems should appear->"{{myitem}}</h2>
    </div>
  </div>
   </div>

 </body>

 </html>`enter code here`
Sign up to request clarification or add additional context in comments.

Comments

0

So it turns out web site uses swig which conflicts with angularjs.

It uses swig for template var which was conflicting with angularjs' use of {{}}, preventing this very simple example from working. Thanks for responses ....

See this other fix for swig/angular conflict if you don't want to use ng-bind

1 Comment

Oh yea simple fix is just to use ng-bind instead of {{}}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.