2 Replies - 1854 Views - Last Post: 18 May 2015 - 05:11 AM

#1 Wolverine89  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 120
  • Joined: 14-January 14

Angularjs browserify app is not defined

Posted 12 May 2015 - 02:54 AM

Hi guys,

Im developing a website using AngularJS framework !I required the game_controller.js in the app.js but the following error appears anyone got a suggestion how i can solve this.

Uncaught ReferenceError: app is not defined2 @ game_controller.js:3s @ _prelude.js:1(anonymous function) @ _prelude.js:11.../partials/game/game_controller.js @ app.js:11s @ _prelude.js:1e @ _prelude.js:1(anonymous function) @ _prelude.js:1

I use brackets as SDK and if i type in ap.... brackets allready suggest app so it is recognized in that file.

'use strict';
 
// Create Mahjong_Mayhem app
var angular = require('angular');
var app = angular.module('Mahjong_Mayhem', [ 
    'ngRoute', 
]);
 
// Include dependencies
require('angular-route');
require('../partials/game/game_controller.js');
 
// Creating routes
app.config(['$routeProvider', function($routeProvider) {
    $routeProvider.
        when('/home',{
            templateUrl: 'partials/home/home.html'
    }).
        when('/game/list', {
            templateUrl: 'partials/game/game_list.html',
            controller: 'ListController'
    }).
        when('/game/new', {
            templateUrl: 'partials/game/game_create.html'
    }).
    otherwise({
        redirectTo: '/home'
    });  
}]);



'use strict';
 
app.controller('ListC ontroller', ['$scope', '$http', function($scope, $http) {
    $http.get("http://mahjongmayhem.herokuapp.com/games").success(function(data){
        console.log(data);
        $scope.games = data;
    });
}]);




Is This A Good Question/Topic? 0
  • +

Replies To: Angularjs browserify app is not defined

#2 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1829
  • View blog
  • Posts: 5,761
  • Joined: 15-January 14

Re: Angularjs browserify app is not defined

Posted 12 May 2015 - 11:45 AM

What does the require function do? I don't see it in the documentation for Angular. Is it asynchronous, does it require a callback?
Was This Post Helpful? 0
  • +
  • -

#3 Programmist  Icon User is offline

  • Refactorer in Chief
  • member icon

Reputation: 255
  • View blog
  • Posts: 1,843
  • Joined: 02-January 06

Re: Angularjs browserify app is not defined

Posted 18 May 2015 - 05:11 AM

The error message says:

Quote

Uncaught ReferenceError: app is not defined...game_controller.js:3


Now look at line 3 of game_controller.js:
app.controller(...


You're referencing the variable app, but it's not defined in that file. Do this to retrieve the previously-defined module and assign it to app.
 var app = angular.module('Mahjong_Mayhem');

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1