Question

I am following the HotTowel Angular course by John Papa with the latest Hot Towel version 2.1.0, however I am getting an Error "config is not defined" occurring when my query is executed.

 function getServerPartials() {
        var orderBy = 'Activated, Label, Serial, IsActive';
        var servers;

        return EntityQuery.from('Servers')
            .select('ServerId, Name, Serial, Activated, IsActive')
            .orderBy(orderBy)
            .toType('Server')
            .using(manager).execute()
            .to$q(querySucceeded, _queryFailed);

        function querySucceeded(data) {
            servers = data.results;
            log('Retrieved [Server Partials] from remote data source', servers.length, true);
            return servers;
        }

    }
    function _queryFailed(error) {
        var msg = config.appErrorPrefix + 'Error retreiving data.' + error.message;
        logError(msg, error);
        throw error;
    }

app.run(['$route','config.breeze',  function ($route) {
    // Include $route to kick start the router.       

}]);  

The error has to do with the .to$q(querySucceeded, _queryFailed); do I have to add something in the app section as I know breeze.to$q library is no longer needed or present.

Was it helpful?

Solution

Your getServerPartials function uses config which is an angular service in the app. You need to inject config in your factory, controller, directive, whatever. Otherwise you get this issue. I do not see what type of object the function is contained within. In other words ... if its wrapped in a factory, inject config.

OTHER TIPS

The problem is with this line:

app.run(['$route','config.breeze',  function ($route) {
// Include $route to kick start the router.       
}]);  

Config is not defined. You have to define it. It also needs to have a property, "breeze", with presumably some really specific stuff you tutorial tells you how to hook up.

If you are following John's Pluralsight examples, you may have your app.run in the wrong place. It looks like you have it in your datacontext.js. In the PS course, John calls it at the end of the app.js like so: (the config.js does not have a breeze property in either the Part 1 or part 2 versions)

     // Handle routing errors and success events
app.run(['$route', '$rootScope', '$q', 'routemediator',
    function ($route, $rootScope, $q, routemediator) {
        // Include $route to kick start the router.
        breeze.core.extendQ($rootScope, $q);
        routemediator.setRoutingHandlers();
    }]);        
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top