0

Maybe I'm doing something wrong here because I can not get this work. am I missing something?

services.js

$http({
    method : 'GET',
    url : 'angular.properties'
}).success(function (data, status, headers, config) {
    console.log("good");
}).error(function (data, status, headers, config) {
    console.log("error: " + data); // It's printing this.
});

angular.properties

{ 
    "url": "http://localhost", 
    "port": "",
    "default_language": "es" 
}

app structure

app structure

Error

enter image description here

Gruntfile.js

'use strict';

module.exports = function (grunt) {

  grunt.initConfig({
    connect: { 
      server: {
        options: {
          port: 9000,
          base: 'app/'
        }
      }
    },
    watch: { 
      project: {
        files: ['app/**/*.js', 'app/**/*.html', 'app/**/*.json', 'app/**/*.css'],
        options: {
          livereload: true
        }
      }
    },
  });

  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-contrib-watch');

  grunt.registerTask('default', ['connect', 'watch']);

};

ANSWER

The content of the folder 'app' is what I should put on my server. So I just need the content of app, AND my angular.properties was out of this folder. That's the mistake. Now is working :) The correct structure of this is:

enter image description here

4
  • what do you mean by angular.properties? Commented Aug 31, 2015 at 17:46
  • a simple properties file. like: stackoverflow.com/questions/19100225/… Commented Aug 31, 2015 at 17:48
  • @skubski url seems same in console error.. Commented Aug 31, 2015 at 17:51
  • @PankajParkar you are right! Commented Aug 31, 2015 at 17:51

2 Answers 2

0

I assume your main.js is your service so you're actually starting your site from /module and not /app which means your .properties file exist in the directory below the root of the website.

If you move your angular.properties file into the module directory, your original code should work.

Sign up to request clarification or add additional context in comments.

1 Comment

The content of the folder 'app' is what I should put on my server. So I just need the content of app, AND my angular.properties was out of this folder. That's the mistake. Now is working :) Thanks for expand the vision to dealing with this.
0

I would recommend to define angular.properties as a value. You can also declare it as a constant but then you can only inject it into controllers and services.

angular.module(NAME).value('properties', { 
    "url": "http://localhost", 
    "port": "",
    "default_language": "es" 
});

This way you can easily inject it into your service and then consume it in the call

$http({
    method : 'GET',
    url : properties.url
}).success(function (data, status, headers, config) {
    console.log("good");
}).error(function (data, status, headers, config) {
    console.log("error: " + data); // It's printing this.
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.