AngularJS RouteParams AngularJS RouteParams angularjs angularjs

AngularJS RouteParams


There are two problems in your code:

  1. Definition of "roomController"

    app.controller('roomController', ["$scope", "Auth", "Ref",                "AuthService", "roomService","$http",                function($scope, Auth, Ref, AuthService, roomService,                $http,box) {})

Just match the parameters and their declarations and you will see that you missed a declaration for the "box" parameter. The correct "roomController" definition should be like this:

app.controller('roomController', ["$scope", "Auth", "Ref", "AuthService", "roomService","$http", "box",        function($scope, Auth, Ref, AuthService, roomService, $http,box)
  1. "box" provider. You defined "setColor" method as the configuration method of provider, but you are trying to use it as a provider result method. The corrected version should be like this:

    app.provider("box", function (){    var hex = "SomeColor";    var UID = 3;    return {        $get: function ()        {            return {                color: hex,                setColor: function (value)                {                    UID = value                }            }        }    }})

Angular Providers

Answer to EDIT2:

You defined HashProvider. To configure it in app.config you should pass argument as HashProvider (not just Hash, BUT when you will try to use it anywhere except app.config you should inject it as Hash). So your app.config declaration should be like this:

app.config(function ($routeProvider, $cookiesProvider, HashProvider)

...and to let you access the getHash method it's necessary to move it to the provider configuration, for example like this:

app.provider("Hash", function (){    var UID = 0;    var _getHash = function()    {        return UID;    };    return {        getHash: _getHash,        $get: function ()        {            return {                setHash: function (value)                {                    UID = value;                },                getHash: _getHash            }        }    }})

Answer to EDIT3:

Now I got what you are trying to do. And the thing is that you are trying to do it wrong :). The right way is more simple. You have to configure route with param, for example like this:

.when('/:hash', {    template: '<h1>TEST TEST</h1>',    controller: 'any controller'})

And place it just after your last route. After that, in controller you may access hash by using $routeParams object. For example like this:

$routeParams.hash

And after that in controller you may analyze if it's right hash and do necessary stuff, or redirect user somewhere if hash is invalid.