0
votes

I deployed a simple AngularJS app(which is working perfectly fine on local) into Heroku, then looks like "ng-repeat" stops working for some reason, there is no error from heroku logs. hopefully someone could give some hints.

project source:

run it on local:

  1. npm installn.
  2. node index.js

run it on heroku:

  1. git clone

  2. heroku create

  3. git add .

  4. git commit -m "initial commit"

  5. git push heroku master

  6. heroku ps:scale web=1

  7. heroku open

index.js

var express = require('express');
var app = express();
var path = require('path');

app.set('port', (process.env.PORT || 5000));

app.use(express.static(__dirname + '/scripts'));
app.use(express.static(__dirname + '/scripts/lib'));
app.use(express.static(__dirname + '/scripts/services'));
app.use(express.static(__dirname + '/scripts/controllers'));

app.get('/',function(req,res){
  res.sendFile(path.join(__dirname+'/index.html'));
  //__dirname : It will resolve to your project folder.
});

app.listen(app.get('port'), function() {
  console.log('Node app is running on port', app.get('port'));
});

index.html

<html ng-app="albumsApp">
	
	<head>
		<meta charset="utf-8">
		<title>Albums Store</title>

		<!-- CSS -->
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css">
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/3.3.0/ekko-lightbox.min.css">
		<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">

		<!-- JS Libs -->
		<script src="jquery.min.js"></script>
		<script src="bootstrap.min.js"></script>
		<script src="ekko-lightbox.min.js"></script>
		<script src="angular.min.js"></script>
		<script src="angular-animate.min.js"></script>
		<script src="lodash.min.js"></script>

		<!-- modules / services / controllers -->
		<script src="app.module.js"></script>
		<script src="album_service.js"></script>
		<script src="album.js"></script>
		<script src="user.js"></script>

		<!-- lightbox delegation -->
		<script type="text/javascript">
			$(document).ready(function ($) {

				// delegate calls to data-toggle="lightbox"
				$(document).delegate('*[data-toggle="lightbox"]:not([data-gallery="navigateTo"])', 'click', function(event) {
					event.preventDefault();
					return $(this).ekkoLightbox({
						onShown: function() {
							if (window.console) {
								return console.log('Checking our the events huh?');
							}
						},
						onNavigate: function(direction, itemIndex) {
							if (window.console) {
								return console.log('Navigating '+direction+'. Current item: '+itemIndex);
							}
						}
					});
				});

				//Programatically call
				$('#open-image').click(function (e) {
					e.preventDefault();
					$(this).ekkoLightbox();
				});

			});
		</script>

	</head>

	<body>
		<h1>Albums Library</h1>
		Search: <input ng-model="query" type="text"/>

		<div ng-controller="albumCtrl">
			<table class="pure-table pure-table-bordered">
				<thead>
					<tr>
						<th><a href="" ng-click="sortField = 'id'; reverse = !reverse" >Album ID</a></th>
						<th>Album Title</th>
						<th><a href="" ng-click="sortField = 'userId'; reverse = !reverse" >User Name</a></th>
					</tr>
				</thead>

				<tr ng-repeat="album in albums | orderBy:sortField:!reverse | filter:query">
					<td>{{album.id}}</td>
					<td>
						<div id="title_container" class="pure-g"> 
							<div class="pure-u-3-5">{{album.title}}</div>
							<div class="pure-u-1-5"><input type="checkbox" ng-model="shouldShow" /></div>
							<div class="pure-u-1-5" ng-show="shouldShow">
								<a href="{{album.url}}" data-toggle="lightbox">
									<img ng-src="{{album.thumbnailUrl}}" class="img-responsive">
								</a>
							</div>
						</div>
					</td>
					<td>{{album.userId}}</td>
				</tr>
			</table>
		</div>

		<!-- testing data
		<div ng-controller="userCtrl" class="pure-u-1-2">
			<table class="pure-table pure-table-bordered">
				<thead>
					<tr>
						<th><a href="" ng-click="sortField = 'id'; reverse = !reverse" >User ID</a></th>
						<th><a href="" ng-click="sortField = 'name'; reverse = !reverse" >User Name</a></th>
						<th>Email</th>
					</tr>
				</thead>

				<tr ng-repeat="user in users | orderBy:sortField:!reverse | filter:query">
					<td>{{user.id}}</td>
					<td>{{user.name}}</td>
					<td>{{user.email}}</td>
				</tr>

			</table>
		</div>
		-->

		
	</body>
</html>

package.json

{
  "name": "angularjs-study",
  "version": "1.0.0",
  "description": "project for AngularJS self-studying with fake data from JSONplaceholder & faker.js",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "express": "4.13.3",
    "gzippo": "^0.2.0",
    "path": "^0.12.7"
  },
  "engines": {
    "node": "0.12.7"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/igxz/angularjs-study.git"
  },
  "keywords": [
    "angularjs",
    "node",
    "heroku",
    "express"
  ],
  "author": "Stephen Zhang",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/igxz/angularjs-study/issues"
  },
  "homepage": "https://github.com/igxz/angularjs-study#readme"
}

scripts/services/album_service.js

angular
	.module('albumsApp')
	.factory('albumService', albumService);

function albumService($http){
	return {
		fetch_all_albums: function(){
				return $http.get('http://jsonplaceholder.typicode.com/albums');
			},

		fetch_all_users: function(){
				return $http.get('http://jsonplaceholder.typicode.com/users');
			},

		fetch_all_photos: function(){
				return $http.get('http://jsonplaceholder.typicode.com/photos');
			},

		id_to_name: function(albums, users){
				angular.forEach(albums, function(album){
						var userName = _.select(users, function(u){
							return u.id === album.userId;
						})[0].name;
						album.userId = userName;
					});
			},

		add_photo_urls: function(albums, photos){
				angular.forEach(albums, function(album){
						var matchedPhoto = _.select(photos, function(p){
							return p.albumId === album.id;
						})[0];

						var thumbnailUrl = matchedPhoto.thumbnailUrl;

						var url = matchedPhoto.url;

						// add key/value
						album['thumbnailUrl'] = thumbnailUrl;
						album['url'] = url;
				});
			}
		};
}

Procfile

web: node index.js

I got screen shots of how output looks like both from local & heroku, bud I don't have enough reputation to post here : (


Solved

it's working on Netify with no code update, I guess it could be heroku env issue then, Netify makes process much easier it can be accessed from http://json-placeholder-example.netlify.com/

1
anything in the console? - user2954587
did you mean heroku console? - Stephen Z
Try to cut down your problem or deploy it some where for people to see. Cause most people reading this probably won't bother looking at your entire code repository on git and then run heroku to find your problem. And your statement of "ng-repeat stops working" is very vague. - kevin
@StephenZ no browser console - user2954587
made it working on Netify with no code update, I guess it could be heroku env issue then, Netify makes process much easier it can be accessed from json-placeholder-example.netlify.com - Stephen Z

1 Answers

0
votes

If the ng-repeat was working before and stopped and no error is being thrown the most likely reason is that there's no data being retrieved. Test your data retrieval outside of the page to see if that's the case.