1

I'm trying to use the constant methods for setting environment variables. When I want to access the constant it gives a Method instead of a String as I would expect.

I'm using a config.js:

angular.module("config", [])

.constant("endPoint", "http://localhost:8080");

Then I'm injecting it in my App.js:

angular.module('jbehaveWebApp', ['ngRoute', 'mgcrea.ngStrap', 'ui.bootstrap','config']).config(function($routeProvider)

After which I'm getting it as a parameter in my controller:

angular.module('jbehaveWebApp').controller('StoryCtrl', ['$scope', '$http', 'filterFilter','endPoint',
function StoryCtrl($scope, $http, endPoint) 

When I'm logging the endpoint var the browser sends the following string:

function (array, expression, comparator) {
    if (!isArray(array)) return array;

    var comparatorType = typeof(comparator),
        predicates = [];

    predicates.check = function(value) {
      for (var j = 0; j < predicates.length; j++) {
        if(!predicates[j](value)) {
          return false;
        }
      }
      return true;
    };

    if (comparatorType !== 'function') {
      if (comparatorType === 'boolean' && comparator) {
        comparator = function(obj, text) {
          return angular.equals(obj, text);
        };
      } else {
        comparator = function(obj, text) {
          if (obj && text && typeof obj === 'object' && typeof text === 'object') {
            for (var objKey in obj) {
              if (objKey.charAt(0) !== '$' && hasOwnProperty.call(obj, objKey) &&
                  comparator(obj[objKey], text[objKey])) {
                return true;
              }
            }
            return false;
          }
          text = (''+text).toLowerCase();
          return (''+obj).toLowerCase().indexOf(text) > -1;
        };
      }
    }

    var search = function(obj, text){
      if (typeof text == 'string' && text.charAt(0) === '!') {
        return !search(obj, text.substr(1));
      }
      switch (typeof obj) {
        case "boolean":
        case "number":
        case "string":
          return comparator(obj, text);
        case "object":
          switch (typeof text) {
            case "object":
              return comparator(obj, text);
            default:
              for ( var objKey in obj) {
                if (objKey.charAt(0) !== '$' && search(obj[objKey], text)) {
                  return true;
                }
              }
              break;
          }
          return false;
        case "array":
          for ( var i = 0; i < obj.length; i++) {
            if (search(obj[i], text)) {
              return true;
            }
          }
          return false;
        default:
          return false;
      }
    };
    switch (typeof expression) {
      case "boolean":
      case "number":
      case "string":
        // Set up expression object and fall through
        expression = {$:expression};
        // jshint -W086
      case "object":
        // jshint +W086
        for (var key in expression) {
          (function(path) {
            if (typeof expression[path] == 'undefined') return;
            predicates.push(function(value) {
              return search(path == '$' ? value : (value && value[path]), expression[path]);
            });
          })(key);
        }
        break;
      case 'function':
        predicates.push(expression);
        break;
      default:
        return array;
    }
    var filtered = [];
    for ( var j = 0; j < array.length; j++) {
      var value = array[j];
      if (predicates.check(value)) {
        filtered.push(value);
      }
    }
    return filtered;
} 

Can someone tell my what I'm doing wrong?

3
  • 2
    Shouldn't it be .controller('StoryCtrl', ['$scope', '$http', 'endPoint',? Commented Jul 18, 2014 at 12:29
  • filterFilter should be endPoint no? Commented Jul 18, 2014 at 12:30
  • Also tried that. Still gives the same result Commented Jul 18, 2014 at 12:30

1 Answer 1

5

This:

function StoryCtrl($scope, $http, endPoint) 

Should be:

function StoryCtrl($scope, $http, filterFilter, endPoint) 
Sign up to request clarification or add additional context in comments.

1 Comment

@Eernie if this solves your problem don't forget to mark the answer as correct.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.