MEAN stack polling application not displaying data, possibly not saving it

163 Views Asked by At

Hi I am creating a simple polling application on a MEAN stack. I am using this tutorial to create my application. I have currently just finished step 3 but my application is not behaving as intended.

When I debug in eclipse I am receiving is :

Jshint is telling me that Angular is not defined within my services.js, app.js, controller.js. I have tried moving the script tags all over the place rearranging them in various orders as other examples have advised, but none have removed this error.

EDIT I have included the information from jack_the_ripper into my .jshintrc file. I believe I am still doing something wrong. Here is a copy of my code as requested.

{    
"bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
"curly" : true, // Require {} for every new block or scope.
"eqeqeq" : true, // Require triple equals i.e. `===`.
"forin" : true, // Tolerate `for in` loops without `hasOwnPrototype`.
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef" : true, // Prohibit variable use before definition.
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"noempty" : true, // Prohibit use of empty blocks.
"nonew" : true, // Prohibit use of constructors for side-effects.
"plusplus" : false, // Prohibit use of `++` & `--`. //coding style related only
"regexp" : true, // Prohibit `.` and `[^...]` in regular expressions.
"undef" : true, // Require all non-global variables be declared before they are used.
"strict" : false, // Require `use strict` pragma in every file.
"trailing" : true, // Prohibit trailing whitespaces.


"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
"boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
"eqnull" : false, // Tolerate use of `== null`.
"es5" : true, // Allow EcmaScript 5 syntax. // es5 is default https://github.com/jshint/jshint/issues/1411
"esnext" : false, // Allow ES.next (ECMAScript 6) specific features such as `const` and `let`.
"evil" : false, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"funcscope" : false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
"globalstrict" : false, // Allow global "use strict" (also enables 'strict').
"iterator" : false, // Allow usage of __iterator__ property.
"lastsemic" : false, // Tolerat missing semicolons when the it is omitted for the last statement in a one-line block.
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
"laxcomma" : true, // Suppress warnings about comma-first coding style.
"loopfunc" : false, // Allow functions to be defined within loops.
"maxerr" : 100, // This options allows you to set the maximum amount of warnings JSHint will produce before giving up. Default is 50.
"moz" : false, // This options tells JSHint that your code uses Mozilla JavaScript extensions. Unless you develop specifically for the Firefox web browser you don't need this option.
"multistr" : false, // Tolerate multi-line strings.
"onecase" : false, // Tolerate switches with just one case.
"proto" : false, // Tolerate __proto__ property. This property is deprecated.
"regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
"scripturl" : false, // Tolerate script-targeted URLs.
"smarttabs" : false, // Tolerate mixed tabs and spaces when the latter are used for alignmnent only.
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
"validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function.
"couch" : false, // Enable globals exposed by CouchDB.
"devel" : false, // Allow development statements e.g. `console.log();`.
"dojo" : false, // Enable globals exposed by Dojo Toolkit.
"jquery" : false, // Enable globals exposed by jQuery JavaScript library.
"mootools" : false, // Enable globals exposed by MooTools JavaScript framework.
"node" : true, // Enable globals available when code is running inside of the NodeJS runtime environment.
"nonstandard" : false, // Define non-standard but widely adopted globals such as escape and unescape.
"phantom" : false, //?since version? This option defines globals available when your core is running inside of the PhantomJS runtime environment.
"prototypejs" : false, // Enable globals exposed by Prototype JavaScript framework.
"rhino" : false, // Enable globals available when your code is running inside of the Rhino runtime environment.
"worker" : false, //?since version? This option defines globals available when your code is running inside of a Web Worker.
"wsh" : false, // Enable globals available when your code is running as a script for the Windows Script Host.
"yui" : false, //?since version? This option defines globals exposed by the YUI JavaScript framework.

"nomen" : false, // Prohibit use of initial or trailing underbars in names.
"onevar" : false, // Allow only one `var` statement per function.
"passfail" : false, // Stop on first error.
"white" : false, // Check against strict whitespace and indentation rules.
"globals": { // Globals variables.
    "jasmine": true,
    "angular": true,
    "ApplicationConfiguration": true,
    "browser": true,
    "element": true,
    "io":true,
    "_":false,
    "$":false
    }

    }

Another error I am receiving is when I try and inspect in chrome. The console is responding with :

Error: [$resource:badcfg] Error in resource configuration for action query. Expected response to contain an array but got an object. I do believe this the source of my troubles.It is located in the .\public\js\services.js file ,but have been falling short coming up with a solution for this error although I have tested many supplied online so far.

Edit2 my code for services.js that is not working.

     angular.module('pollServices', ['ngResource']).
      factory('Poll', function($resource) {
        return $resource('polls/:pollId', {}, {
          query: { method: 'GET', params: { pollId: 'polls' }, isArray: true }
        });
      });

When I inspect it in Batarang my model in the scope for the list of polls is always empty even after I have created them.

If you have some spare time and wouldn't mind reviewing my code I have uploaded it to this git repository.

Thank you for your time in advance.

Sincerely,

FredK

1

There are 1 best solutions below

0
On

you should include only the relevant code of your app into the question, because it's easier to spot the issue if you narrow it down, anyway it seems like you are having some common issues that as a angular.js developer you'll find very often.

I'm quoting you on your questions:

Jshint telling me that Angular is not defined within my services.js, app.js, controller.js. I have tried moving the script tags all over the place rearranging them in various orders as other examples have advised, but none have removed this error.

create a file named .jshintrc in your root folder, add angular to your global variables, something like this:

"globals": { // Globals variables.
        "jasmine": true,
        "angular": true,
        "ApplicationConfiguration": true,
        "browser": true,
        "element": true,
        "io":true,
        "_":false,
        "$":false
    }

Error in resource configuration for action query. Expected response to contain an array but got an object.

this is a common scenario when you are doing a query to your rest API and you should configure your $resource service to retrieve an array or a single object, in you case you should use isArray: false in your configuration, for more information look at the resource documentation of how to set up your $resource.